If I install several packages with Python 2.6 (e.g. using easy_install) and then I want to upgrade to Python 2.7, is there a way to upgrade Python and then automatically “import” all those installed packages along with it? Or do they have to be reinstalled?
Two related questions: (1) if a package is installed in a Python 2.6 packages directory, is it legitimate to import it into the PYTHONPATH of a newer Python, like Python 2.7, or must all the packages be reinstalled with Python 2.7? (2) if I use easy_install, how can I tell it to use the newer Python? E.g. 2.7 instead of 2.6? Or should I just reinstall easy_install using Python 2.7 to do this? thanks.
First, this is one of the many reasons you want to use
pipinstead ofeasy_install. (You still needeasy_installto getpipitself, but beyond that, don’t touch it ever again.) If you’d usedpip, you could just do this:That gives you a list of all of the modules you have installed, and their version numbers. Most of the time, you can just take the list of modules (
line.split('==')[0] for line in f) and pass it topip install.But that’s for future reference. For today, you have to piece it together yourself by looking through your
site-packagesdirectory. Fortunately, many things will end up asfoo_bar-1.2.3.4-blah-blah.egg, so all you have to do is guess whether the package is namedfoo-barorfoo_barat PyPI, and usually even if you guess wrong,easy_installorpipwill get the right thing anyway. So, you can’t quite automate it, but you can get close.But yes, however you do it, you do need to reinstall. Anything that requires C extension code has to be recompiled. Pure-Python packages may not need to be changed, but they may, and you’re better safe than sorry. Also, if you try to copy some things over but not others, you’re going to make a big mess of your dependencies.
Don’t do that; reinstall them, as explained above.
You need the 2.7
easy_install. You can usually use a 2.7easy_installwith 2.6 by running, e.g.,python2.6 $(which easy_install), but the other way around isn’t guaranteed to work.And you don’t want to do that anyway. If you want two versions of Python in parallel, you want two versions of
easy_install—normally you want to end up witheasy_install-2.6andeasy_install-2.7, witheasy_installas a symlink to whichever one you consider your “primary” python.