0

Having upgraded the version of python on my Mac OS X 10.6.8 from python 2.6 to python 2.7.10 I am getting the following error when I try to run pip commands in bash:

error –bash: pip: command not found

I have tried installing pip with the command:

sudo easy_install pip

… but am getting the error

python version 2.7.10 can't run /usr/bin/easy_install. Try the alternative(s):

/usr/bin/easy_install-2.5 (uses python 2.5)
/usr/bin/easy_install-2.6 (uses python 2.6)

The problem is I removed these versions of python from my Mac when I updated to 2.7.10

Could anyone please suggest a solution that would help me to execute pip commands in bash?

** updated to show outputs as requested **

$ echo $PATH

/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

$ which -a python

/usr/bin/python

$ which -a pip

# no output

** updated to show further outputs as requested **

$ ls -lh /usr/local/bin/easy_install
lrwxrwxr-x  1 root  admin    74B  6 Sep 12:12 /usr/local/bin/easy_install -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install

$ ls -lh $(which python)
lrwxr-xr-x  1 root  wheel    67B  6 Sep 12:18 /usr/bin/python -> /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python

$ less /usr/local/bin/easy_install
/usr/local/bin/easy_install: No such file or directory
Tom Beare
  • 11
  • 4

2 Answers2

1

I don't know how you uninstalled Python from your computer, but you have left some utilities around that are still referring to older versions of Python.

The uninstall was not done completely or it was not done correctly.

Moving forward now, you have to decide what do you want to do. There are two scenarios:

  1. Run multiple versions of Python. The one that came with the operating system; and another version of your choice. You can then (optionally) set one of those as the default Python version.

  2. Completely remove all versions of Python, and have one installation across the entire system.

The recommended method is #1; as mentioned - there might be some utilities on your system that are relying on the bundled version of Python and may not function after a core-system upgrade. This is especially true on Linux; but less of a factor on Windows (since Python is not bundled with Windows).

According to your system output; your shell and system is still configured against the system-bundled version of Python.

The easiest way for you to move forward is to download the official installer for osx; and have it setup your system for you.

It will also ensure that pip is installed and configured correctly.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
0

Have you tried (re-)installing setuptools from PyPI?

On a related note, removing previously installed Pythons can lead to all sorts of system breakage, as other programs may rely on the old versions. It'd probably be safer to alias your newly installed python in .bashrc, e.g.:

alias python27="/path/to/your/python2.7"

The recommended way of hosting several versions of Python on the same machine is through virtualenv and virtualenvwrapper.

This section on installing packages from the Python Packaging User Guide addresses these issues.

  • Thanks for the answer, I have just followed the instructions and successfully installed setuptools 18.2 from PyPI but am still getting the error `-bash: pip: command not found` when I try to execute pip commands in bash. Worried to hear that removing previously installed versions of python can lead to system breakages.. Should I reinstall them? – Tom Beare Sep 06 '15 at 14:01
  • `setuptools` should have set up `easy_install`. Would you try now to `easy_install pip`? – Maksim Yegorov Sep 06 '15 at 14:08
  • 1
    An alternative would be to download [get-pip.py](https://raw.github.com/pypa/pip/master/contrib/get-pip.py) and run it using `python get-pip.py`. – Maksim Yegorov Sep 06 '15 at 14:13
  • re easy_install pip just tried this and receive the same error code: `python version 2.7.10 can't run /usr/bin/easy_install. Try the alternative(s): /usr/bin/easy_install-2.5 (uses python 2.5) /usr/bin/easy_install-2.6 (uses python 2.6)` Do you know what else I could try? Thanks again for your help – Tom Beare Sep 06 '15 at 14:16
  • I agree that Apple default pythons would better be reinstalled, the discussion [here](http://stackoverflow.com/questions/15456386/remove-preinstalled-python-from-mac-osx-10-8) might help. – Maksim Yegorov Sep 06 '15 at 14:20
  • What about `get-pip.py`? Try locating where `easy_install` was put when you installed `setuptools`, then run it from there. Might be under /usr/local/bin. – Maksim Yegorov Sep 06 '15 at 14:25
  • There is an easy_install file in usr/local/bin. Should I therefore try: `$ usr/local/bin easy_install get-pip.py`. Sorry if this sounds very naive I am relatively new to installing packages. – Tom Beare Sep 06 '15 at 14:36
  • Please post the output when you run `$ /usr/local/bin/easy_install pip` . The script `get-pip.py` is an alternative to installing `pip` via `easy_install` – Maksim Yegorov Sep 06 '15 at 14:41
  • This outputs `-bash: /usr/local/bin/easy_install: No such file or directory`. I am puzzled why as I can see easy_install does exist in /usr/local/bin – Tom Beare Sep 06 '15 at 14:46
  • update: tried navigating to usr/local/bin then running easy_install pip - received same error code: `python version 2.7.10 can't run /usr/bin/easy_install. Try the alternative(s)` etc. – Tom Beare Sep 06 '15 at 14:56
  • What is the output of `$ ls -lh /usr/local/bin/easy_install` ? Please also post the output of `$ ls -lh $(which python)` and `$ less /usr/local/bin/easy_install` – Maksim Yegorov Sep 06 '15 at 15:00
  • I have updated the original post with these, I hope this is informative, thanks again for your ongoing help – Tom Beare Sep 06 '15 at 15:12
  • Running out of options here, but one final thing. Please open the `easy_install` file in editor (follow the path that you found before from `$ ls -lh /usr/local/bin/easy_install`) and edit the first line of the file to read the absolute path of your python (based on your previous output, it should be: `#! /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python `) After saving edited `easy_install`, enter python and try importing pip from within, as follows: `$ python` --> from within python type `from setuptools.command import easy_install; easy_install.main( ["-U","pip"] )` – Maksim Yegorov Sep 06 '15 at 15:37
  • Also, your Path should have your new python first and foremost on your path. Do this from terminal: `$ export PATH=/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH` before what I suggested in the comment above. Also for the future, add the line (`export PATH=/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH`) as the last line in the file that defines `PATH` (could be `.bash_profile`, or `.profile`, or `.bashrc` -- I'm not familiar with Mac defaults) – Maksim Yegorov Sep 06 '15 at 15:46
  • okay I have edited my Path and edited the easy_install file in editor as instructed. When I try and run `from setuptools.command import easy_install; easy_install.main( ["-U","pip"] )` I get a Permission denied error - any idea how I can run it as an administrator from within python? Thanks again, appreciate you have done all you can. – Tom Beare Sep 06 '15 at 16:22
  • One option is to make your `site-packages` writeable by all: `$ sudo chmod a+w /path/to/your/site-packages`. You can always change permissions back to default later if you have any concerns (of course you need to take note of the default permissions now before the change). Next do the whole `from setuptools.command import easy_install; easy_install.main( ... )` spiel as before. `site-packages` could be named `dist-packages` on your distro, to find the path to the folder, invoke `import site; site.getsitepackages()` from python. If needed, you can change other files' permission similarly. – Maksim Yegorov Sep 06 '15 at 16:50
  • At this point it might be best to reinstall Python from scratch using `homebrew` or `macports` (I'd first retrace your most recent installation steps to make sure that unsuccessful installation is removed). This might be your starting point for [Mac specific instructions](http://docs.python-guide.org/en/latest/starting/install/osx/) – Maksim Yegorov Sep 06 '15 at 17:01