ImportError with VirtualEnv

I am trying to use VirtualEnv for the Flask application that I am creating, since everyone has recommended that I do this. After creating my virtual environment, I installed the libraries that I needed using pip when the environment was activated. I ran into ImportError problems with this script. The code works fine when I'm not in a virtual environment.

My script:

#!/usr/bin/python import sc2reader ... ... 

When I try to run it, I get the following:

 (flaskapp) xxxx@xxxx-VirtualBox :~/flaskapp/bin$ ./test.py Traceback (most recent call last): File "./test.py", line 3, in <module> import sc2reader ImportError: No module named sc2reader 

I tried modifying shebang to reflect my VirtualEnv path for Python, but that didn't fix anything. The library is in my site-packages folder in my virtual environment, so I'm not sure why I get ImportError.

I have never used VirtualEnv before, so I guess I configured it incorrectly so that it doesn't see my package sites.

+4
source share
1 answer

Try using

 #!/usr/bin/env python 

like a shebang. If this does not work, try to see what is the result of which python .

+5
source

Source: https://habr.com/ru/post/1481570/


All Articles