How do I install pip for Python 2.6 on OS X?

倖福魔咒の 提交于 2019-12-05 10:14:26

Download the source file here. Then do

>> cd ~/Downloads
>> tar -xzvf pip-7.0.1.tar.gz 

(replacing ~/Downloads if necessary). Then

>> cd pip-7.0.1
>> sudo python2.6 setup.py install
>> cd

(the last cd is used to leave the build directory). Now you should be able to run

>> python2.6 -c 'import pip;print pip.__version__'
7.0.1

By default, pip (when installed from source) should be installed into /usr/local/bin. To check:

>> /usr/local/bin/pip --version
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)

Now you can install your favorite packages using

>> /usr/local/bin/pip install package
>> python2.6 -c 'import package'

If you have conflicting versions of pip in /usr/local/bin you can try this ridiculous one liner:

>> python -c 'import os;dir="/usr/local/bin";[ os.system("echo %s/%s: && %s/%s --version"%(dir,s,dir,s)) for s in os.listdir("/usr/local/bin") if s.startswith("pip")  ]'
/usr/local/bin/pip:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)
/usr/local/bin/pip2:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)
/usr/local/bin/pip2.6:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)

to find the one linked to py2.6. (in my case they are all the same)

By default Homebrew provides pip command via: brew install python.

So try installing Python using Homebrew. Try to not use sudo when working with brew.

To verify which files are installed with your Python package, try:

$ brew list python
/usr/local/Cellar/python/2.7.9/bin/pip
/usr/local/Cellar/python/2.7.9/bin/pip2
/usr/local/Cellar/python/2.7.9/bin/pip2.7
...

which should consist pip.

After installation you should symlink your formula's installed files by:

brew link python

which should create the right symbolic links (such as /usr/local/bin/pip pointing to your Cellar/python/2.?.?/bin/pip)

If you've permission issue, you may fix it by:

sudo chgrp -R admin /usr/local /Library/Caches/Homebrew
sudo chmod -R g+w /usr/local /Library/Caches/Homebrew

and make sure your user is in admin group (id -Gn $USER).

Then re-link it again:

brew unlink python && brew link python

To test dry-run, unlink and run: brew link -n python to see links of files which brew would link.

After linking is successful, make sure that your PATH system variable have /usr/local, if not, add:

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

to your ~/.bashrc file.

If successful, your pip should work now.


If you don't want to use Homebrew or you have two Pythons installed on your Mac, you can alternatively install it via:

sudo easy_install pip

Your error:

Download error: unknown url type: https

means that your Python can't handle HTTPS protocol without having SSL support, so try installing: openssl package (on Linux either libssl-dev or openssl-devel).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!