简体   繁体   中英

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.

在此处输入图片说明

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

在此处输入图片说明

I'm using python3.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM