Install python-numpy in the Virtualenv environment

后端 未结 2 670
青春惊慌失措
青春惊慌失措 2021-02-08 23:48

I would like to install the python-numpy in the Virtualenv environment. My system is Ubuntu 12.04, and my python is 2.7.5. First I installed the Virtualenv by

$         


        
2条回答
  •  情书的邮戳
    2021-02-09 00:34

    apt-get will still install modules globally, even when you're in your new virtualenv.

    You should either use pip install numpy from within your virtual environment (easiest way), or else compile and install numpy from source using the setup.py file in the root of the source directory (slightly harder way, see here).

    I'd also thoroughly recommend you take a look at virtualenvwrapper, which makes managing virtual environments much friendlier.

    Edit:

    You should not be using sudo, either to create your virtual environment or to install things within it - it's a directory in your home folder, you don't need elevated permissions to make changes to it. If you use sudo, pip will make changes to your global site packages, not to your virtual environment, hence why you weren't able to install numpy locally.

    Another thing to consider is that by default, new virtualenvs will inherit from the global site-packages - i.e. if Python can't find a module locally within your virtualenv, Python will also look in your global site packages *. In your case, since you'd already installed numpy globally (using apt-get), when you then try to pip install numpy in your virtual environment, pip sees that numpy is already in your Python path and doesn't install it locally.

    You could:

    1. Pass the --no-site-packages option when you create your virtualenv. This prevents the new virtualenv from inheriting from the global site packages, so everything must be installed locally.

    2. Force pip to install/upgrade numpy locally, e.g. using pip install -U --force numpy


    * As of v1.7, the default behaviour of virtualenv is to not include the global site-packages directory. You can override this by passing the --system-site-packages flag when creating a new virtual environment.

提交回复
热议问题