运行 python3 时“此包不应在 Python 3 上访问”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42214414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"This package should not be accessible on Python 3" when running python3
提问by user1883614
I was trying to use virtualenv to switch between python versions before learning that I could use both python and python3 on my Mac.
在了解到我可以在 Mac 上同时使用 python 和 python3 之前,我试图使用 virtualenv 在 python 版本之间切换。
I was able to fix my python 2.7 version so that still works fine however, now when I run python3, I get this error:
我能够修复我的 python 2.7 版本,因此它仍然可以正常工作,但是,现在当我运行 python3 时,出现此错误:
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 125, in <module>
import functools
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I've looked online for this error but most of the conversation was on fixing up the patch and then upgrading virtualenv. However, this still doesn't fix my issue.
我在网上查找了这个错误,但大部分对话都是关于修复补丁然后升级 virtualenv。但是,这仍然不能解决我的问题。
python3 -V: Python 3.6.0
virtualenv --version: 15.1.0
env | egrep -i 'python|virtualenv': PYTHONPATH=/usr/local/lib/python2.7/site-packages:
回答by Charles Duffy
Your environment contains PYTHONPATH=/usr/local/lib/python2.7/site-packages
您的环境包含 PYTHONPATH=/usr/local/lib/python2.7/site-packages
This doesn't work with Python 3 for obvious reasons. To remove it:
由于显而易见的原因,这不适用于 Python 3。要删除它:
unset PYTHONPATH
回答by anjaneyulubatta505
I solved my problem with below command
我用下面的命令解决了我的问题
sudo pip install virtualenv --upgrade
virtualenv -p python3 env