无法导入Django。您确定它已安装并在您的PYTHONPATH上可用

时间:2018-10-18 14:53:54

标签: python django postgresql

我正在创建一个startproject,并且尝试使用命令行迁移默认的Django模式:

manage.py migrate

结果是:"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?"

我正在使用虚拟环境,并且安装了下一个依赖项:

Django==2.1.2
psycopg2==2.7.5
pytz==2018.5 

当然,我正在尝试在激活的虚拟环境下进行迁移。

有人知道我的版本兼容性是否有问题?我的PostgreSQL是10。

pip list command

1 个答案:

答案 0 :(得分:2)

这很可能意味着您不是从激活的virtualenv内运行命令

C:\> my_venv\Scripts\activate

(my_venv) C:\>  (type your command now)

产生的错误消息是if unable to import django.core.management

try:
    from django.core.management import execute_from_command_line
except ImportError as exc:
    raise 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?"
    ) from exc

您可以使用与错误命令相同的环境进入Python控制台(例如,在您的情况下,在同一控制台窗口中键入python),然后尝试手动导入该模块,然后{{3} }。