我在Mac上安装Python 3.5时遇到了问题。我想在运行Django开发服务器时使用Python 3.5作为解释器。我尝试时遇到了这个问题(我知道我必须安装virtualenv,请阅读下面的内容):
$ python3 manage.py runserver
Traceback (most recent call last):
File "manage.py", line 7, in <module>
from mezzanine.utils.conf import real_project_name
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Mezzanine-4.0.1-py3.5.egg/mezzanine/utils/conf.py", line 7, in <module>
from django.conf import global_settings as defaults
ImportError: No module named 'django'
第一个是我在我的虚拟环境中尝试安装默认安装在Python 2.7上的pip包时:
pip install django==1.9rc2
Collecting django==1.9rc2
Downloading Django-1.9rc2-py2.py3-none-any.whl (6.4MB)
100% |████████████████████████████████| 6.4MB 66kB/s
Installing collected packages: django
Successfully installed django-1.9rc2
我使用Django所以我也尝试过第一次安装虚拟环境。首先我用pip尝试了,但是没有用。
那么我如何设置以便在使用Python解释器和虚拟环境时我的Python3.5是默认用法?我无法弄清楚这一点,或者我在我的过程中做错了什么。
编辑:
感谢您的回答和评论。我尝试了两种解决方案,同样的错误仍然存在。见下面的输出:
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 Django/
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 14, in <module>
import shutil
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 10, in <module>
import fnmatch
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/fnmatch.py", line 15, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/functools.py", line 21, in <module>
from collections import namedtuple
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/collections/__init__.py", line 16, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/Library/Python/2.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.
我的virtualenv版本: 13.1.2
答案 0 :(得分:3)
您的错误与已知的virtualenv
bug有关python-future
并混合2.7和3.x模块路径有关,解决方法是将virtualenv
降级为版本&lt; 12.04,链接中建议12.0.2
。
答案 1 :(得分:2)
首先,如果你打算使用多个版本的python,那么你必须使用Virtual Env.Also然后使用以下命令创建你的virtualenv,以便它使用python 3.5作为默认环境:
virtualenv -p python3 envname
然后在virtualenv中安装django。激活你的virtualenv