11

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?

4
  • What operating system are you using? How are you installing it? Which of the files at that website did you actually download, and what did you do with it? Commented Sep 17, 2014 at 21:44
  • Uninstall 3.4 and make sure directories are deleted, then install numpy for 2.7. After everything is done, install python 3.4. Commented Sep 17, 2014 at 21:44
  • Who told you that's 2.7-specific? When I go to that page, I get a source download which, according to the README, says "This release supports Python 2.6 - 2.7 and 3.2 - 3.4." Commented Sep 17, 2014 at 21:44
  • 1
    @Feign: That is an extreme solution and shouldn't be necessary. Commented Sep 17, 2014 at 21:45

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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…
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.
@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.
@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.
@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.
1

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

3 Comments

The fact that he's downloading a file from that site suggests he's not using pip.
+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.
@BrenBarn: I included an alternative solution already using setup.py.
1

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

Comments

0

Just one other note on issues like this. I had a similar problem with Python 2.7 libraries not being found, because I had miniconda installed for a Python virtual environment that was hijacking calls to python from other programs. After deleting the minconda directory in my home the problem went away and python libraries that were properly installed were found again.

Comments

0

Note-This answer is particularly for Windows PC which has both Python2 & Pyhton3 installed on it.

Both the versions of Python has their different directories somewhat like

"C:\Python27\" ----for python2

"C:\Python35\" ---- for python3

*(or it depends on what path you chose while installing Python**)*

pip GENERALLY exist under the directory "C:\Python**\Scripts"

there you can find exe files like:

pip.exe/pip2.exe/pip2.7.exe ----for python2

pip3.exe/pip3.5.exe ----for python3

to install packages on python2:

use

Python27\Scripts\pip2.exe install package_name

(where the 1st argument is the path of exe file, it might differ for your system)

to install packages on python3:

use

Python35\Scripts\pip3.exe install package_name

there is no need to uninstall any version of python to achieve the task.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.