[英]Issues that could happen if importing site-packages from python2.6 to be used with python2.7?
[英]How can I move my Python2.6 site-packages into Python2.7?
我剛剛在ArchLinux上運行了一個更新,它給了我Python3和Python2.7。
在此更新之前,我使用的是Python2.6。 我安裝的模塊位於/usr/lib/python2.6/site-package
。 我現在想要使用Python2.7並刪除Python2.6。
如何將Python2.6模塊移動到Python2.7中?
它就像做mv /usr/lib/python2.6/site-packages/* /usr/lib/python2.7/site-packages
一樣簡單嗎?
你的問題確實是,“我怎樣才能將python 2.6中的軟件包放到我的[new] python 2.7配置中?復制文件是否有效?”
我建議以2.6套餐的方式將軟件包安裝到2.7中。 我不建議你復制文件。
安裝文件的合理方法是:
easy_install的
像這樣獲得easy_install: wget http://python-distribute.org/distribute _setup.py && sudo python ./distribute_setup.py
點子安裝
得到這樣的點子: sudo easy_install pip
不是一個完整的答案:它不像mv
那么簡單。 這些文件被字節編譯成.pyc文件,這些文件特定於python版本。 所以至少你必須重新生成.pyc文件。 (刪除它們也應該足夠了。)可以使用compileall.py完成重新生成。
大多數發行版都提供了比這樣的手動擺弄更加靈活的升級Python模塊的方法,所以也許有人能夠給出Arch特定部分的答案嗎?
干凈的方式是重新安裝。 然而,對於許多(如果不是大多數)純python包, mv
方法將起作用
您可能想要' easy_install yolk
',可以將其作為' yolk -l
'調用,以便為您提供所有已安裝軟件包的易於閱讀的列表。
嘗試這樣的事情:
#!/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.