1

I have two versions of python- 2.7.6 & 2.7.9 and numpy is installed for python 2.7.6 . I can't understand how to install numpy for python 2.7.9.

When I use pip2 install --upgrade numpy, it installs and updates for python 2.7.6.

How do I install numpy particularly for python 2.7.9?

*****edit*****

I am trying to find the location of python 2.7.9.

If i type python or python2, I am using python 2.7.9. which -a python gives me two paths, /usr/bin/python and /usr/local/bin/python and when I used the first path, it gives me this output- Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python2.7/dist-packages Cleaning up...

If I used the second path, i get this output- /usr/local/bin/python: No module named pip

which -a pip command gives /usr/local/bin/pip /usr/bin/pip

which -a easy_install gives /usr/local/bin/easy_install /usr/bin/easy_install

which -a python gives /usr/local/bin/python /usr/bin/python

*****edit2*****

My OS is Ubuntu 14.04lts.

/usr/local/bin/pip --version gives pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7).

/usr/bin/pip --version gives pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)

/usr/local/bin/easy_install --version gives setuptools 32.1.2 from /usr/local/lib/python2.7/dist-packages (Python 2.7)

/usr/bin/easy_install --version gives setuptools 3.3

/usr/local/bin/python --version gives Python 2.7.9

/usr/bin/python --version gives Python 2.7.6

*****edit3*****

sudo /usr/local/bin/easy_install pip gives following output-

Searching for pip
Best match: pip 1.5.4
Adding pip 1.5.4 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip

*****edit4*****

sys.path = [
'/home/kevmepls',
'/home/kevmepls/Documents/DeepLearning-Caffe/caffe/python',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/home/kevmepls/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/site-packages',
]
USER_BASE: '/home/kevmepls/.local' (exists)
USER_SITE: '/home/kevmepls/.local/lib/python2.7/site-packages' (exists)
ENABLE_USER_SITE: True
Kevin George
  • 119
  • 2
  • 13
  • How about uninstall 2.7.6, including `numpy`, then install a fresh `numpy` on 2.7.9. Or even completely purge your system of all python installations and then do this. Seems like a much cleaner option. – pretzlstyle Jan 03 '17 at 17:18
  • I think that the canonical answer to this question is that it's better that you start using virtual environments (If you're using `numpy`, anaconda is nice). Barring that, presumably there is a `pip` specific to each python installation. You need to find the `pip` that goes with the 2.7.9 installation and use that one. – mgilson Jan 03 '17 at 17:18
  • I thought it was a bad idea to remove any python version as I may accidentally remove some system dependencies? – Kevin George Jan 06 '17 at 11:37

2 Answers2

4

Like this:

/path/to/python279 -m pip install --user numpy

If you are seeing the error No module named pip, then first install pip as described below:

  1. Download this file: get_pip.py
  2. Execute sudo /path/to/python279 get_pip.py
  3. Try again the /path/to/python279 -m pip install --user numpy
wim
  • 338,267
  • 99
  • 616
  • 750
  • Hi wim, sorry for the late reply. How do I exactly find the location of python 2.7.9? I can only find for python 2.7.6 which is in usr/local/lib . – Kevin George Jan 06 '17 at 11:36
  • Well, how do you normally run python 2.7.9? Try checking the output of `which -a python`. – wim Jan 06 '17 at 16:59
  • I edited the question to show the output of `which -a python`. – Kevin George Jan 07 '17 at 01:16
  • OK. You'll have to first install pip using `easy_install`. – wim Jan 07 '17 at 01:21
  • I actually have pip installed already and I can see the file in `usr/local/bin` . – Kevin George Jan 07 '17 at 04:32
  • You have it installed but it's not for the correct interpreter. Use the command `which pip`, edit the file that points at, and modify the first line (which starts with `#!` and then a path to a python interpreter) so that it's using the right interpreter. – wim Jan 07 '17 at 16:12
  • I changed the path to both #!/usr/bin/python2.7 and #!/usr/bin/python2 but i get this output- Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python2.7/dist-packages Cleaning up.... So it is still linking with python 2.7.6 instead of python 2.7.9. – Kevin George Jan 09 '17 at 06:07
  • I'm still having a problem with installing numpy for python 2.7.9. It always installs to my python 2.7.6 instead. – Kevin George Jan 14 '17 at 01:09
  • Try this command: `/usr/local/bin/python -m easy_install pip`. Then repeat the command in my answer. If that doesn't work, edit your question and add more details: your os/platform, the output of `which -a easy_install`, `which -a pip` and `which -a python`. – wim Jan 14 '17 at 04:07
  • Even though the file easy_install is there, the command `/usr/local/bin/python -m easy_install pip` gives me this error `/usr/local/bin/python: No module named easy_install`. Also I've edited the question. – Kevin George Jan 14 '17 at 06:25
  • For each of the 6 executables listed, please add the details of the output of `executable -- version`. I also asked what os/platform you're using. – wim Jan 14 '17 at 19:00
  • I've edited the question. Btw thanks wim for helping out with my problem patiently. – Kevin George Jan 16 '17 at 04:46
  • Looks like the distribution in local is the right one. So try this: `/usr/local/bin/easy_install pip` and then `/usr/local/bin/python -m pip install --user numpy` – wim Jan 16 '17 at 06:48
  • pip seems to be installed but when I enter `/usr/local/bin/python -m pip install --user numpy`, i get this output - `/usr/local/bin/python: No module named pip` I've edited the question to show the output of `/usr/local/bin/easy_install pip` – Kevin George Jan 16 '17 at 09:35
  • You mentioned in [an earlier comment](http://stackoverflow.com/questions/41448804/how-to-install-numpy-for-python-2-7-9/41448929#comment70288724_41448929) that you tried modifying the `#!` line, but you didn't modify it to the correct interpreter. Try editing the file at `/usr/local/bin/pip` so that it's using `#!/usr/local/bin/python` and then doing `/usr/local/bin/pip install --user numpy`. If that still doesn't work, please add the output of the following command: `/usr/local/bin/python -m site`. We will get there eventually....! – wim Jan 16 '17 at 17:56
  • After doing the above edits, `/usr/local/bin/pip install --user numpy` gives me this error - `Traceback (most recent call last): File "/usr/local/bin/pip", line 6, in from pkg_resources import load_entry_point ImportError: No module named pkg_resources` . Do you have any idea how to solve this? See the question edit for output of `/usr/local/bin/python -m site` – Kevin George Jan 17 '17 at 03:57
  • Somehow `setuptools` package has been deleted in your environment. Please try the answer shown [here](http://stackoverflow.com/q/7446187/674039) and see if it resolves that problem. – wim Jan 17 '17 at 18:22
0

I believe this has to do with your path variables. Currently, I believe your path variable points to your installation of Python 2.7.6. Check your path variable for python, and hopefully changing it to the correct installation fixes your issue.

Tyler R
  • 474
  • 2
  • 6
  • 15