I'm really confused with how virtualenv deals with packages. I'm on OSX and installed python2 and 3 with Homebrew followed by pip install virtualenv
.
in terminal:
cd Virtualenv/MyTestEnv
. bin/activate
pip install numpy
would install numpy into my virtualenv folder which can only be accessed if I run my program within that env. From what I read, it does this by modifying the system $PATH. However when I try running a program with numpy I can't:
(MyTestEnv)___________________
| ~/desktop/Python @ My-MBP (chronologos)
| => ./wordsrt.py
Traceback (most recent call last):
File "./wordsrt.py", line 2, in <module>
import numpy
ImportError: No module named numpy
the program has only two lines:
#!/usr/bin/env python
import numpy
And when I do pip list
numpy is shown as installed? Is it a problem with the hashbang?
Help would be appreciated!
I managed to solve my problem.
Firstly I modified my bashrc to only allow pip when virtualenv is on:
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
syspip(){
PIP_REQUIRE_VIRTUALENV="" pip "$@"
}
Then to ensure user-installed binaries take precedence I added this to my bash_profile
export PATH=/usr/local/bin:$PATH