Installing numpy for Python 2.7 while also having Python 3.4 installed?

36,961

Solution 1

I recommend installing with pip.

pip install numpy

If this doesn't work on windows then download the binary from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and convert it to a wheel before installing.

pip install wheel
wheel convert path/to/binary
pip install numpy_wheel 

Pip is recommended because you can uninstall.

To check where you are installing to

pip -V

You may have an environmental variable path to the wrong pip.

Solution 2

Assuming that you are using, or at least you should use pip to install the library. You can specify the python version to be installed by changing the suffix, e.g. pip-2.7 install numpy.

pip install numpy
pip-2.7 install numpy
pip-3.4 install numpy

As an alternative, in case that you do not want to use pip is to download and install the library using setup with a similar technique.

python setup.py install
python2.7 setup.py install
python3.4 setup.py install

Solution 3

Your PATH isn't setup correctly.

C:> where pip

Should tell you which pip it is trying to use, and it is likely whichever one it found on your PATH first...

So, instead, you will want to run it as

C:> C:\mypython2install\pip.exe install numpy

Or, setup your path correctly. See here

Share:
36,961
David
Author by

David

Updated on March 10, 2020

Comments

  • David
    David about 4 years

    I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7.

    I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/

    However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn't work, obviously.

    How do I do this?

  • BrenBarn
    BrenBarn over 9 years
    The fact that he's downloading a file from that site suggests he's not using pip.
  • abarnert
    abarnert over 9 years
    +1. And if you're not using pip to install the library, either (a) you're using binary installers for your platform (whether Christoph Gohlke's or something that comes from an apt or rpm repo or similar), in which case you just need to choose the right binary, or (b) whatever you're doing, you should stop doing that and instead use pip, in which case this answer will fix all your problems.
  • eandersson
    eandersson over 9 years
    @BrenBarn: I included an alternative solution already using setup.py.
  • abarnert
    abarnert over 9 years
    What do you mean "on windows this won't work"? That's how I installed numpy on my Windows environment… Of course you need to install a C compiler and follow the instructions to get it working, but at some point you're going to run into a library that Gohlke doesn't have, or need a newer version, so it really is worth learning how to do…
  • justengel
    justengel over 9 years
    pip on windows doesn't always work. Sometimes they don't have the library compiled for windows. In the past numpy has not worked for me; maybe it is working now.
  • BrenBarn
    BrenBarn over 9 years
    @abarnert: That's a judgement call. Getting compilation set up on Windows is not trivial, especially for something like numpy. If the OP is on windows, it is probably useful to have a solution that is based on running an executable installer.
  • abarnert
    abarnert over 9 years
    @BrenBarn: Saying "on Windows this will not work" isn't a judgment call, it's just plain wrong. Saying "on Windows you may not want to do this", that's a different story, and in fact, I'd agree. Almost all users should start off with Gohlke's libraries, at the very least to make sure their setup works and they understand it, before learning to build things.
  • BrenBarn
    BrenBarn over 9 years
    @abarnert: Yes, I meant the part about it being worth learning how to install a C compiler. As for the rest, I think it has only recently become the case that pip install works for numpy, so I wouldn't be surprised if it didn't work for someone who had installed Python/pip some time ago.