Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip using system python osx

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?

like image 816
Navin Aggrawal Avatar asked May 28 '11 00:05

Navin Aggrawal


People also ask

How do I run Python pip on Mac?

To use the get-pip script to install PIP on Mac:Open the Terminal app via the Launchpad. In the Terminal, type curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py and press Enter. Allow curl time to download the script onto your Mac. Once it's done, type python3 get-pip.py and press Enter.

Does pip work on Mac?

Pip is a command that you can use on the Linux or Mac command line. You can select a package from here.

Does Mac have pip by default?

Policy for non-brewed Python bindings These should be installed via pip install <package> . To discover, you can use pip search or https://pypi.org. Note: macOS's system Python does not provide pip . Follow the pip documentation to install it for your system Python if you would like it.


1 Answers

UPDATE: I strongly recommend installing CPython by building from source (example), and then creating virtual environments to work in.


Summarizing the above, installing pip using Macports:

sudo port install py39-pip

results in an installation of a MacPorts port named py39-pip.

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

Note that Python files in:

  • /usr/bin are of the preinstalled Python of macOS
  • /usr/local/bin are installed by MacPython, available from python.org
  • /opt/local/bin are installed by MacPorts.

The actual executable files can be found by ls -ls applied to the various Python-related symbolic links found in each of the above bin directories).

To ensure that the Python installed by MacPorts is called first, place /opt/local/bin within the runtime environment's PATH earlier than /usr/bin and /usr/local/bin. This can be done in the file ~/.bash_profile or the file ~/.bashrc (which one depends on your system and configuration). For example, writing

export PATH=/opt/local/bin:$PATH

last in ~/.bashrc will have this effect (assuming that the intended shell will source the file ~/.bashrc).

After the paths have been appropriately defined, the system still fails to find a pip command in the Macports bin directory, because it is installed as /opt/local/bin/pip3.9. The file /opt/local/bin/pip is not 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/pip3.9 /opt/local/bin/pip
like image 96
Ioannis Filippidis Avatar answered Sep 22 '22 01:09

Ioannis Filippidis