7

I installed python26 using macports, so the correct python on my system is /opt/local/bin/python

However, when I do

sudo pip install <packagename>

It gives me

sudo pip install <somepackage>                                           
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/basecommand.py", line 126, in main
    self.run(options, args)
  File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/commands/install.py", line 215, in run
    import setuptools
ImportError: No module named setuptools

Storing complete log in /Users/navin/.pip/pip.log

And so, I suspect that it is using the system python. I've installed distribute (which contains setuptools) via their site instructions. I installed pip via an installer as well. I somehow managed to clobber the setuptools for the system python I think, so that's why I'm having this problem now :(

What do I do to get pip working again?

Navin Aggrawal
  • 179
  • 1
  • 2
  • 10
  • as it turns out I also installed pip via macports but the script-installed one takes precedence. I think removing my script-installed pip will fix the problem but I dont know how! – Navin Aggrawal May 28 '11 at 00:30
  • What's the output from `which pip` and `echo $PATH`? – Rob Cowie May 28 '11 at 00:32
  • /Users/navin/bin:/usr/local/bin:/opt/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/navin/code/jruby/bin:/Users/navin/.bin:/Users/navin/.ec2/bin:/Library/Application Support/VMware Fusion:/Users/navin/.rvm/bin – Navin Aggrawal May 28 '11 at 00:47

5 Answers5

14

Summarizing the above, installing pip using Macports with:

sudo port install py27-pip

results in an installation of a package named py27-pip.

However, no /opt/local/bin/pip is installed and port select pip or port select py27-pip both fail (in contrast to a port select python). Changing things in the bin directory of another distribution is not generally recommended.

Note that /usr/bin python links point to the pre-installed python by Apple, /usr/local/bin point to those installed by MacPython from python.org, whereas /opt/local/bin is where Macports install their links. The actual Library installations can be found by ls -ls applied to the various python files in each bin directory).

To ensure that the Macports files are called, export the path for Macports last in your .bash_profile. For example, if you installed Macports and then happened to install a binary distribution from python.org, you will end having its path later in you ~/.bash_profile, so it will come first in the path variable and Macpython will be shadowing Macports.

After ensuring that the paths are appropriately set, the system still fails to find a pip command in the Macports bin directory, because it is installed as pip-2.7 and no pip is automatically created.

As a result, the system continues searching the path and if e.g. Macpython is added to the path some place later and has pip installed, then that pip will show up.

This can be avoided by the command proposed above:

sudo ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip
Ioannis Filippidis
  • 8,272
  • 8
  • 66
  • 96
  • 5
    Using Macports 2.3.1 & the following now works `sudo port select --set pip pip27` – Hal Sep 29 '14 at 14:40
12

Remove pip from /usr/local/bin with sudo rm /usr/local/bin/pip.

If you have installed pip with macports, which pip should then show /opt/local/bin/pip. If not, install pip again by following the instructions here. As long as which python shows the /opt/local installation, it should work. If it doesn't, you will need to edit your PATH env variable.

Rob Cowie
  • 21,066
  • 6
  • 59
  • 56
3

Here is my setup to get pip working with macports and set py26-pip as the default pip

sudo port install py26-pip && sudo port select --set pip py26-pip

after install finishes run to see the help information for pip

pip --help

after you may need to update your path to include the bin files installed by pip edit .bash_profile to include something like

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH
1

You should have the python and pip installed in /opt/local/bin/ prior to those installed in /usr/local/bin/.

Also, you should check to execute which python and whether the pip was installed in /opt/local/bin/pip.

cocoatomo
  • 5,062
  • 2
  • 12
  • 12
0

I found I needed to ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip. For some reason macports didn't built that link, even when you try activating that version of python or pip.

kenny
  • 2,979
  • 3
  • 23
  • 28