telkins
telkins

Reputation: 10540

ImportError with VirtualEnv

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

My script:

#!/usr/bin/python

import sc2reader
...
...

When I try to run it I get this:

(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've tried changing the shebang to reflect my VirtualEnv path for Python, but that didn't fix anything. The library is found in my site-packages folder in my virtual environment, so I'm not sure why I'm getting the ImportError.

I've never used VirtualEnv before so I'm assuming I configured it wrong so it's not seeing my site-packages.

Upvotes: 4

Views: 1379

Answers (1)

Marcio Cruz
Marcio Cruz

Reputation: 2069

Try using

#!/usr/bin/env python

as the shebang. If that does not work, try seeing what is the output of which python.

Upvotes: 5

Related Questions