简体   繁体   English

无法从Venv运行Django Manage.py

[英]Can't Run Django Manage.py from Venv

I'm trying to run manage.py makemigrations for my django app, and I'm getting a "Couldn't import Django" message. 我正在尝试为我的django应用程序运行manage.py makemigrations,并且我收到了“无法导入Django”消息。

I know how venv works and I'm sure my environment includes Django. 我知道venv是如何工作的,我确信我的环境包括Django。 See below; 见下文; I try to run manage.py (running into the error), and then I run $ django-admin --version, and it shows the version of Django. 我尝试运行manage.py(运行到错误中),然后运行$ django-admin --version,它显示了Django的版本。

    (venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ sudo python manage.py makemigrations contacts
Traceback (most recent call last):
  File "manage.py", line 18, 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?
(venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ django-admin --version
2.0.9
(venv) emmett@emmett-HP:~/PycharmProjects/onramp_crm$ 

This is a django-cookiecutter project using Pycharm Pro edition. 这是一个使用Pycharm Pro版本的django-cookiecutter项目。 I've deleted the onramp_crm/venv folder and completely reinstalled the venv, setting up a new interpreter in Pycharm as well. 我删除了onramp_crm / venv文件夹并完全重新安装了venv,并在Pycharm中设置了一个新的解释器。 Logged out & restarted Ubuntu, restarted Pycharm, everything I can think of. 登出并重新启动Ubuntu,重新启动Pycharm,我能想到的一切。

Remove the sudo from sudo python manage.py makemigrations contacts . sudo python manage.py makemigrations contacts删除sudo

Using sudo will use your system version of Python, which, it seems, does not have Django installed. 使用sudo将使用你的系统版本的Python,它似乎没有安装Django。 Without sudo you'll use the venv, which has Django. 如果没有sudo你将使用具有Django的venv。

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

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