José Carlos
José Carlos

Reputation: 2922

Module not found with virtual environment

I can run my app from the console that there is in pyCharm but If I try to run my app from a shell my app doesn't find "pymysql" module.

The module is installed in my project in a virtual environment. You can see in the next image how is installed this module.

enter image description here

And If try to run my app from the shell I've got this error:

enter image description here

I'm using python3.

What am I doing wrong? Is there any easy way to access to the module?

Upvotes: 0

Views: 1536

Answers (1)

Sraw
Sraw

Reputation: 20224

There are several ways:

  1. activate virtual env: source venv/bin/activate.
  2. directly use specific python: venv/bin/python main.py
  3. Surely you can temporarily add venv/bin to your PATH, that's almost the same as the first option: export PATH=full/path/to/bin:$PATH

Generally I recommend the first option. But sometimes you may want to use the second one. For example, you want to use this python in a crontab script.

Upvotes: 2

Related Questions