繁体   English   中英

我尝试启动时无法导入Django错误

[英]Couldn't import Django error when I try to startapp

我通常在PC上工作,但开始在我的Mac上处理项目。 我运行Python 3,当我开始一个新项目时,我做了以下事情:

1)在主项目文件夹中,安装virtualenv并激活它。

2)安装Django和Gunicorn

3)启动项目

当我尝试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?

尝试使用

python -m pip install django

据我所知,这是最安全的方式

我有同样的问题,请确保你激活virtualenv,因为一旦你关闭cmd它就不再被激活:

在cmd中使用env\\Scripts\\activate

现在cmd应该有(env)就像这样: (env) c:\\users\\user\\PROJECT\\..

现在您可以输入: python manage.py runserver

当我使用Pycharm时,我也遇到了同样的问题。 我通过添加以下内容解决了

import sys
  sys.path.append('/Users/et/PycharmProjects/Jieba_Analyzer/venv/lib/python3.6/site-packages')

to manage.py

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM