Installing numpy for Python 2.7 while also having

2020-07-04 05:12发布

问题:

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?

回答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.



回答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


回答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



回答4:

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.



回答5:

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.