Install python-numpy in the Virtualenv environment -
i install python-numpy in virtualenv environment. system ubuntu 12.04, , python 2.7.5. first installed virtualenv
$ sudo apt-get install python-virtualenv
and set environment by
$ mkdir myproject $ cd myproject $ virtualenv venv new python executable in venv/bin/python installing distribute............done.
activated by
$ . venv/bin/activate
installed python-numpy in environment by
$ sudo apt-get install python-numpy
however, tried import numpy in python in environment after steps above. python told me "no modules named numpy". whereas, numpy imported in python globally. tried remove , install many times not work. beginner of both python , linux.
apt-get
still install modules globally, when you're in new virtualenv
.
you should either use pip install numpy
within virtual environment (easiest way), or else compile , install numpy
source using setup.py
file in root of source directory (slightly harder way, see here).
i'd thoroughly recommend take @ virtualenvwrapper
, makes managing virtual environments friendlier.
edit:
you should not using sudo
, either create virtual environment or install things within - it's directory in home folder, don't need elevated permissions make changes it. if use sudo
, pip
make changes global site packages, not virtual environment, hence why weren't able install numpy
locally.
another thing consider by default, new *. in case, since you'd installed virtualenvs
inherit global site-packages
- i.e. if python can't find module locally within virtualenv
, python in global site packagesnumpy
globally (using apt-get
), when try pip install numpy
in virtual environment, pip
sees numpy
in python path , doesn't install locally.
you could:
pass
--no-site-packages
option when createvirtualenv
. prevents newvirtualenv
inheriting global site packages, must installed locally.force
pip
install/upgradenumpy
locally, e.g. usingpip install -u --force numpy
* as of v1.7, default behaviour of virtualenv
not include global site-packages
directory. can override passing --system-site-packages
flag when creating new virtual environment.
Comments
Post a Comment