无法导入Django。您确定已在PYTHONPATH环境变量中安装并使用该变量吗?

时间:2018-06-30 05:46:31

标签: python django environment-variables virtual pythonpath

我正在使用Ubuntu 16.04。现在,我开始我的第一个Django项目。请检查此错误:

(unix-9PXH2taC) unix@unix:~/Desktop/django/test_project$** python manage.py runserver
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'

上述异常是以下异常的直接原因:

Traceback (most recent call last):
File "manage.py", line 14, in <module>
) from exc
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?

出了什么问题?

1 个答案:

答案 0 :(得分:0)

您是如何安装的?

对于pip和conda,请检查您是否处于正确的环境中。

如果您进行了apt安装(或apt-get安装),则只有在您的主目录中获取.bashrc时,PYTHONPATH才会反映出来。注销和登录(或在终端中键入source〜/ .bashrc)。