Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an OS X system where I need to install a module for python 2.6. Both pip and easy_install-2.6 are failing:

# /usr/bin/easy_install-2.6 pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Download error: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Download error: unknown url type: https -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

Downloading get_pip.py and running it with the stock OS X-supplied python 2.6:

# python2.6 ./get_pip.py 
Traceback (most recent call last):
  File "./get_pip.py", line 17868, in <module>
    main()
  File "./get_pip.py", line 162, in main
    bootstrap(tmpdir=tmpdir)
  File "./get_pip.py", line 82, in bootstrap
    import pip
  File "/tmp/tmpVJBvaW/pip.zip/pip/__init__.py", line 15, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/vcs/subversion.py", line 9, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/index.py", line 30, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/wheel.py", line 34, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/_vendor/__init__.py", line 92, in load_module
ImportError: No module named 'pip._vendor.distlib.scripts'


$ python2.6 --version
Python 2.6.9

With python2.7, either method works fine.

like image 270
Virgil Gheorghiu Avatar asked May 30 '15 00:05

Virgil Gheorghiu


People also ask

Does Python 2.6 have pip?

pip works with CPython versions 2.6, 2.7, 3.3, 3.4, 3.5 and also pypy. This means pip works on the latest patch version of each of these minor versions (i.e. 2.6. 9 for 2.6, etc).

What version of Python is pip on Mac?

To check your PIP version on a Mac:Open the Terminal app. In the Terminal, type pip –version and press Enter. Alternatively, type python3 -m pip –version and press Enter.

How do I install pip on a specific version?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .


2 Answers

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)

like image 169
dermen Avatar answered Oct 02 '22 21:10

dermen


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).

like image 25
kenorb Avatar answered Oct 02 '22 20:10

kenorb