Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install numpy in Python virtualenv

I've created virtualenv for Python 2.7.4 on Ubuntu 13.04. I've installed python-dev.

I have the error when installing numpy in the virtualenv.

Maybe, you have any ideas to fix?

like image 317
karavanjo Avatar asked Sep 13 '13 11:09

karavanjo


People also ask

How do I import numpy in Visual Studio?

To install numpy, select pip from the dropdown for Python Environment, then type numpy and click on the “install numpy from PyPI” as shown below. Similarly search for scipy and install it using pip.


3 Answers

The problem is SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.

so do the following in order to obtain 'Python.h'

make sure apt-get and gcc are up to date

sudo apt-get update    
sudo apt-get upgrade gcc

then install the python2.7-dev

sudo apt-get install python2.7-dev

and I see that you have most probably already done the above things.

pip will eventually spit out another error for not being able to write into /user/bin/blahBlah/dist-packages/ or something like that because it couldn't figure out that it was supposed to install your desiredPackage (e.g. numpy) within the active env (the env created by virtualenv which you might have even changed directory to while doing all this)

so do this:

pip -E /some/path/env install desiredPackage

that should get the job done... hopefully :)

---Edit---

From PIP Version 1.1 onward, the command pip -E doesn't work. The following is an excerpt from the release notes of version 1.1 (https://pip.pypa.io/en/latest/news.html)

Removed -E/--environment option and PIP_RESPECT_VIRTUALENV; both use a restart-in-venv mechanism that's broken, and neither one is useful since every virtualenv now has pip inside it. Replace pip -E path/to/venv install Foo with virtualenv path/to/venv && path/to/venv/pip install Foo

like image 150
samkhan13 Avatar answered Oct 17 '22 15:10

samkhan13


If you're on Python3 you'll need to do sudo apt-get install python3-dev. Took me a little while to figure it out.

like image 43
nebffa Avatar answered Oct 17 '22 13:10

nebffa


If you're hitting this issue even though you've installed all OS dependencies (python-devel, fortran compiler, etc), the issue might be instead related to the following bug: "numpy installation thru install_requires directive issue..."

Work around is to manually install numpy in your (virtual) environment before running setup.py to install whatever you want to install that depends on numpy.

eg, pip install numpy then python ./setup.py install

like image 13
kejbaly2 Avatar answered Oct 17 '22 14:10

kejbaly2