简体   繁体   English

如何将Python2.6站点包移动到Python2.7中?

[英]How can I move my Python2.6 site-packages into Python2.7?

I just ran an update on ArchLinux which gave me Python3 and Python2.7. 我刚刚在ArchLinux上运行了一个更新,它给了我Python3和Python2.7。

Before this update, I was using Python2.6. 在此更新之前,我使用的是Python2.6。 The modules I have installed reside in /usr/lib/python2.6/site-package . 我安装的模块位于/usr/lib/python2.6/site-package I now want to use Python2.7 and remove Python2.6. 我现在想要使用Python2.7并删除Python2.6。

How can I move my Python2.6 modules into Python2.7 ? 如何将Python2.6模块移动到Python2.7中?

Is it as simple as doing mv /usr/lib/python2.6/site-packages/* /usr/lib/python2.7/site-packages ? 它就像做mv /usr/lib/python2.6/site-packages/* /usr/lib/python2.7/site-packages一样简单吗?

Your question is really, "How can I get the packages I have in python 2.6 into my [new] python 2.7 configuration? Would copying the files work?" 你的问题确实是,“我怎样才能将python 2.6中的软件包放到我的[new] python 2.7配置中?复制文件是否有效?”

I would recommend installing the packages into 2.7 the same way you did your 2.6 packages. 我建议以2.6套餐的方式将软件包安装到2.7中。 I would not recommend you copy the files. 我不建议你复制文件。

Reasonable ways to install the files are: 安装文件的合理方法是:

  1. easy_install easy_install的

    Get easy_install like this: wget http://python-distribute.org/distribute _setup.py && sudo python ./distribute_setup.py 像这样获得easy_install: wget http://python-distribute.org/distribute _setup.py && sudo python ./distribute_setup.py

  2. pip install 点子安装

    Get pip like this: sudo easy_install pip 得到这样的点子: sudo easy_install pip

  3. apt-get install apt-get install
  4. wget and untar wget and untar

Not a complete answer: It is not as simple as a mv . 不是一个完整的答案:它不像mv那么简单。 The files are byte compiled into .pyc files which are specific to python versions. 这些文件被字节编译成.pyc文件,这些文件特定于python版本。 So at the very least you'd have to regenerate the .pyc files. 所以至少你必须重新生成.pyc文件。 (Removing them should be sufficient, too.) Regenerating can be done using compileall.py. (删除它们也应该足够了。)可以使用compileall.py完成重新生成。

Most distributions offer a saner way to upgrade Python modules than manual fiddling like this, so maybe someone can else can give the Arch specific part of the answer? 大多数发行版都提供了比这样的手动摆弄更加灵活的升级Python模块的方法,所以也许有人能够给出Arch特定部分的答案吗?

The clean way would be re-installing. 干净的方式是重新安装。 However, for many if not most of pure python packages the mv approach would work 然而,对于许多(如果不是大多数)纯python包, mv方法将起作用

您可能想要' easy_install yolk ',可以将其作为' yolk -l '调用,以便为您提供所有已安装软件包的易于阅读的列表。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果从python2.6导入要与python2.7一起使用的站点包,可能会发生问题? - Issues that could happen if importing site-packages from python2.6 to be used with python2.7? 没有VirtualEnv的Python2.7中的站点包 - Site-Packages in Python2.7 without VirtualEnv 如何手动将文件夹复制到/app/.heroku/python/lib/python2.7/site-packages/? - How to manually copy folder to /app/.heroku/python/lib/python2.7/site-packages/? 如何忽略〜/ .local / lib / python2.7 / site-packages中的python模块? - How to ignore python module in ~/.local/lib/python2.7/site-packages? 将 django 从 python2.6 更改为 python2.7 - change django from python2.6 to python2.7 如何在Linux下的/usr/local/lib/python2.7/site-packages下安装Pip - how to Install Pip under /usr/local/lib/python2.7/site-packages in Linux 当我也有Python2.7(OS X)时,virtualenv仅创建/lib/Python2.6 - virtualenv only creates /lib/Python2.6 when I also have Python2.7 (OS X) “/lib/python2.7/site-packages/不支持.pth文件”在MacOS上安装pip - “/lib/python2.7/site-packages/ does NOT support .pth files” installing pip on MacOS ImportError:dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so - ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so 找不到:/lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv - Not found : /lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM