Python import-site error with multiple versions
I'm using a shared machine. I'm trying to install Python 2.6 for a project that is using Pysco (unsupported on 2.7), and there is an existing install of 2.7 on the machine that I cannot remove without breaking other people's projects.
I'm using 32-bit binaries of Python on Windows 7.
When I try to start Python 2.6, I get this error:
'import-site' failed; use -v for traceback
It looks like Python 2.6 is trying to import modules from Python 2.7, which is causing the failure (see output below). Does anybody know what might be causing this, and how it could be fixed? Thanks!
Running with the -v option gives the following output
# 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 User开发者_如何学JAVADict
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
Try to use virtualenv. It is used to separate many instances of python and it's libraries - you can have as many virtual environments as possible: python 2.5 , 2.6 , 2.7, whatever - with any combinations of libraries - so you can have for example five python 2.6 instances with different sets of libraries configured.
Start from http://pypi.python.org/pypi/virtualenv
I know this is an old post, but I recently solved the same problem. It's simply a matter of updating the environment path to include the new version.
Python 2.6 'import site' failed error with 2.7 installed
精彩评论