我通常在PC上工作但是开始在我的Mac上处理项目。我运行Python 3,当我开始一个新项目时,我做了以下事情:
1)在主项目文件夹中,安装了virtualenv并激活它。
2)安装Django和Gunicorn
3)startproject
当我尝试python3 manage.py startapp www时出现无法导入Django的错误。以下是终端中的内容:
(venv) AB:directory AB$ pip freeze
Django==1.10
gunicorn==19.6.0
(venv) AB:directory AB$ ls
directory manage.py
(venv) AB:directory AB$ python3 manage.py startpap www
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
答案 0 :(得分:11)
尝试使用
python -m pip install django
据我所知,这是最安全的方式
答案 1 :(得分:4)
我遇到了同样的问题,请确保你激活了virtualenv,因为一旦你关闭cmd它就不再被激活了:
cmd中的 env\Scripts\activate
现在cmd应该具有(env),如下所示:(env) c:\users\user\PROJECT\..
现在您可以输入:python manage.py runserver
答案 2 :(得分:0)
使用Pycharm时,我也遇到同样的问题。我通过添加来解决它:
import sys
sys.path.append('/Users/et/PycharmProjects/Jieba_Analyzer/venv/lib/python3.6/site-packages')
to manage.py