Question

Problem

I can't seem to get my packages to install to the correct site-packages directory.

Background

I wanted to upgrade to python 3.3 but I found that I still need python2.6 in order to use yum (it isn't configured for python3). And so I have both on my system.

Separate pip and easy_install for each version???

The issue is that when I download a package, and run "python setup.py install" I find that it is installed in python2.6. I have tried using pip and easy_install but they do the same. I have read that a solution is to have different versions of pip (pip_2.6 and pip_3.3). But I can't find a way to download the separate versions. One work around is to give the "-d PathToSitePackages" argument in pip but this is inelegant.

other programs not using the newer version

Another issue is that I find that when I use systems such as sphinx, they use the old version of python. I can't seem to figure out how to get them to use the newer version of python.

Was it helpful?

Solution

First, Python is explicitly designed to make it easy to have Python X.Y and Python V.W at the same time if X != V. PEP 394 explains the details, but basically, python3 will always mean a 3.x version, and if python also means a 3.x version, python2 will mean a 2.x version. The same should be true for all well-behaved tightly-integrated scripts like pip or ipython.

This is a good thing, because many POSIX platforms (most linux distros, OS X, etc.) include code that depends on some particular version of Python, so you have to be able to have that version, but often you want a newer version for your own code.

On most platforms, even if X == V, things are still easy as long as Y != W, because a default installation will also give you pythonX.Y, and set things up so well-behaved scripts do the same. This part isn't mandated by the PEP, so some linux distros don't do it, or do it in a different way. But fortunately, you just want 2.6 and 3.3, so you don't have to worry about this part.


So, if you just install pip in any of the normal ways using Python X.Y, , you will get some new packages in Python X.Y's site-packages, probably a script named pip-X.Y (note that it's a hyphen, not an underscore), and usually a symlink pip and/or pip3 to that script. So, you don't have to do anything to get this.

In particular, testing this sequence (the way the documentation recommends for system-wide installation):

$ curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
$ sudo python3.3 ez_setup.py
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python3.3 get-pip.py

… I ended up with exactly that.

If you didn't, you'll have to give us details on your platform, how you installed each Python (presumably 2.6 came as part of the system installation, but not 3.3), and how you installed each pip.


If you instead did sudo yum install python-pip and sudo yum install python33-pip (or python3-pip), exactly what you get is up to the distro, so it's possible that you'll end up with just, say, pip (for 2.6) and pip-3.3 (for 3.3), rather than pip-2.6 and pip-3.3 and symlinks pip and pip3. Looking at the RPM contents for various distros' packages, it looks like the standard name for Red-Hat-like systems is python3-pip, with a symlink to pip-python3, and sometimes other names besides.


Anyway, unless you mix and match different methods, you're almost certain to get some way to distinguish the two pip versions.


If worst comes to worst, and you've just got a script named pip, and whichever one you installed last overwrote the one you installed first… You can always install the first one, cp pip pip-2.6, install the second, and mv pip pip-3.3; ln -s pip-2.6 pip; ln -s pip-3.3 pip3.

Or, if you can't even do that, the script is trivial, something like this:

#!/usr/local/bin/python3.3
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.2.1','console_scripts','pip-3.3'
__requires__ = 'pip==1.2.1'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==1.2.1', 'console_scripts', 'pip-3.3')()
    )

And you can just make a copy and s/3.3/2.6/g the copy (you may also have to replace the 1.2.1 if you somehow installed different versions of pip into the different site-packages) and it will work.

But it really, really shouldn't come to this, however. Both setuptools and pip respect PEP 394, and any package manager that doesn't has to have some rules or its python 3 packages are useless. So, if you think these tricks are necessary, you probably did something wrong earlier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top