0

I have a one-line script in my project which imports a package (flask_mail). I'm running it in virtualenv. If I execute python script.py I get ImportError: No module named flask_mail. If in the same folder, with the same virtualenv activated I open the python console and run the same command from my script.py file (import flask_mail) I get no errors whatsoever.

Virtualenv was created with the following command: virtualenv venv and then activated source venv/bin/activate

What am I doing wrong here?

Romeo Mihalcea
  • 9,714
  • 12
  • 50
  • 102
  • How do you open the python console? Does adding `import sys; print sys.executable` print the same path as doing the same in the console? – Martijn Pieters Jan 13 '13 at 22:23
  • running the cmd in console gives the venv path which is the correct one but running the script returns the global python path. I don't know why. – Romeo Mihalcea Jan 13 '13 at 22:25
  • 2
    You are not using the same python then. `python` is still finding the global python, your virtual env is not active. I also asked you how you are opening the python console. – Martijn Pieters Jan 13 '13 at 22:26
  • Obviously not but it says active in my console when running the script with venv activated.... – Romeo Mihalcea Jan 13 '13 at 22:27
  • You should probably do `cd venv` then `source bin/activate`; I don't think it'll make a difference here though. – Martijn Pieters Jan 13 '13 at 22:28
  • Forget the activate script. Run your script using the virtualenv's python absolute path and check it out. If that works something is messing with your `$PATH`. – Hugo Lopes Tavares Jan 15 '13 at 22:21
  • Did you ever solve this? I am having the same problem http://stackoverflow.com/questions/26769541/cant-import-in-a-virtual-enviroment – straykiwi Nov 06 '14 at 01:51

0 Answers0