Python 导入站点错误与多个版本
我在使用一台共享的电脑。我想安装Python 2.6,因为我的项目需要用到Pysco(这个在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
2 个回答
1
我知道这是一篇旧帖子,但我最近也遇到了同样的问题并解决了。其实就是更新环境路径,把新版本加进去就行了。
Python 2.6 'import site' 失败,安装了2.7
2
试着使用virtualenv。它的作用是把不同的Python版本和它们的库分开管理。你可以创建尽可能多的虚拟环境,比如Python 2.5、2.6、2.7等等,甚至可以随意组合不同的库。举个例子,你可以有五个Python 2.6的环境,每个环境里配置不同的库。
可以从这个链接开始了解:http://pypi.python.org/pypi/virtualenv