我正在使用共享计算机。我正在尝试为使用Pysco的项目安装Python 2.6(在2.7上不支持),并且机器上有一个2.7的现有安装,我无法在不破坏其他人的项目的情况下删除。
我在Windows 7上使用32位的Python二进制文件。
当我尝试启动Python 2.6时,我收到此错误:
'import-site' failed; use -v for traceback
看起来Python 2.6正试图从Python 2.7导入模块,导致失败(参见下面的输出)。有人知道可能导致这种情况的原因,以及如何解决这个问题?谢谢!
使用-v选项运行会提供以下输出
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# C:\Python27\Lib\site.pyc matches C:\Python27\Lib\site.py
import site # precompiled from C:\Python27\Lib\site.pyc
# C:\Python27\Lib\os.pyc matches C:\Python27\Lib\os.py
import os # precompiled from C:\Python27\Lib\os.pyc
import errno # builtin
import nt # builtin
# C:\Python27\Lib\ntpath.pyc matches C:\Python27\Lib\ntpath.py
import ntpath # precompiled from C:\Python27\Lib\ntpath.pyc
# C:\Python27\Lib\stat.pyc matches C:\Python27\Lib\stat.py
import stat # precompiled from C:\Python27\Lib\stat.pyc
# C:\Python27\Lib\genericpath.pyc matches C:\Python27\Lib\genericpath.py
import genericpath # precompiled from C:\Python27\Lib\genericpath.pyc
# C:\Python27\Lib\warnings.pyc matches C:\Python27\Lib\warnings.py
import warnings # precompiled from C:\Python27\Lib\warnings.pyc
# C:\Python27\Lib\linecache.pyc matches C:\Python27\Lib\linecache.py
import linecache # precompiled from C:\Python27\Lib\linecache.pyc
# C:\Python27\Lib\types.pyc matches C:\Python27\Lib\types.py
import types # precompiled from C:\Python27\Lib\types.pyc
# C:\Python27\Lib\UserDict.pyc matches C:\Python27\Lib\UserDict.py
import UserDict # precompiled from C:\Python27\Lib\UserDict.pyc
# C:\Python27\Lib\_abcoll.pyc matches C:\Python27\Lib\_abcoll.py
import _abcoll # precompiled from C:\Python27\Lib\_abcoll.pyc
# C:\Python27\Lib\abc.pyc matches C:\Python27\Lib\abc.py
import abc # precompiled from C:\Python27\Lib\abc.pyc
# C:\Python27\Lib\_weakrefset.pyc matches C:\Python27\Lib\_weakrefset.py
import _weakrefset # precompiled from C:\Python27\Lib\_weakrefset.pyc
import _weakref # builtin
'import site' failed; traceback:
Traceback (most recent call last):
File "C:\Python27\Lib\site.py", line 62, in <module>
import os
File "C:\Python27\Lib\os.py", line 398, in <module>
import UserDict
File "C:\Python27\Lib\UserDict.py", line 84, in <module>
_abcoll.MutableMapping.register(IterableUserDict)
File "C:\Python27\Lib\abc.py", line 109, in register
if issubclass(subclass, cls):
File "C:\Python27\Lib\abc.py", line 151, in __subclasscheck__
if subclass in cls._abc_cache:
File "C:\Python27\Lib\_weakrefset.py", line 69, in __contains__
return ref(item) in self.data
TypeError: cannot create weak reference to 'classobj' object
答案 0 :(得分:2)
尝试使用virtualenv。它用于分离python及其库的许多实例 - 你可以拥有尽可能多的虚拟环境:python 2.5,2.6,2.7,等等 - 使用任何库的组合 - 所以你可以拥有例如5个不同的python 2.6实例已配置的库集。
开始答案 1 :(得分:1)
我知道这是一个老帖子,但我最近解决了同样的问题。只需更新环境路径以包含新版本即可 Python 2.6 'import site' failed error with 2.7 installed