How to port Python2.6 site packages to Python2.7?

I just ran the ArchLinux update that gave me Python3 and Python2.7.

Prior to this update, I used Python2.6. The modules I installed are in /usr/lib/python2.6/site-package . Now I want to use Python2.7 and remove Python2.6.

How to port my Python2.6 modules to Python2.7?

Is it as simple as doing mv /usr/lib/python2.6/site-packages/* /usr/lib/python2.7/site-packages ?

+4
source share
5 answers

Your question really is: "How can I get the packages that I have in python 2.6 into my [new] python 2.7 configuration? Will file copying work?"

I would recommend installing packages in 2.7 the same way you did your 2.6 packages. I would not recommend you copy files.

Possible ways to install files:

  • easy_install

    Get easy_install as follows: wget http://python-distribute.org/distribute _setup.py && sudo python ./distribute_setup.py

  • pip install

    Get the pip as follows: sudo easy_install pip

  • apt-get install
  • wget and untar
+1
source

Not the complete answer: it is not as simple as mv . Byte files are compiled into .pyc files that are related to python versions. Therefore, at least you will have to regenerate the .pyc files. (Removing them should also be sufficient.) Regeneration can be performed using compileall.py.

Most distributions offer an easier way to update Python modules than manually driving in this way, so maybe someone else can give some of the answer in Arch?

0
source

A clean way will be reinstalled. However, for many, if not most of the packages of pure python, the mv approach would work

0
source

You might want easy_install yolk , which can be called as yolk -l to give you a list that can be easily read for all installed packages.

0
source

Try something like this:

 #!/usr/bin/env python import os import os.path import subprocess import sys import tempfile def distributions(path): # Extrapolate from paths which distributions presently exist. (parent, child) = os.path.split(path) while child is not '' and not child.startswith('python'): (parent, child) = os.path.split(parent) if len(child) > 0: rel = os.path.relpath(path, os.path.join(parent, child)) ret = [] for distro in os.listdir(parent): if distro.startswith('python'): dir = os.path.join(os.path.join(parent, distro), rel) if os.path.isdir(dir): ret.append((distro, dir)) ret.sort() return ret return [] def packages(dir): return [pkg.split('-')[0] for pkg in os.listdir(dir)] def migrate(old, new): print 'moving all packages found in ' + old[0] + ' (' + old[1] + ') to ' + new[0] + ' (' + new[1] + ')' f = tempfile.TemporaryFile(mode = 'w+') result = subprocess.call( ['which', 'easy_install'], stdout = f, stderr = subprocess.PIPE) f.seek(0) easy_install = f.readline().strip() f.close() if os.path.isfile(easy_install): pkgs = packages(old[1]) success = [] failure = [] for pkg in pkgs: # Invoke easy_install on the package print 'installing "' + pkg + '" for ' + new[0] result = subprocess.call( [new[0], easy_install, pkg]) if result != 0: failure.append(pkg) print 'failed' else: success.append(pkg) print 'success' print str(len(success)) + ' of ' + str(len(pkgs)) + ' succeeded' else: print 'Unable to locate easy_install script' if __name__ == '__main__': package_path = sys.path[-1] distros = distributions(package_path) migrate(distros[0], distros[1]) list(package_path) 
0
source

All Articles