我在 zsh 中有一个正确激活的 venv,因为我可以在提示符开头看到 (venv)
,但是当我尝试使用命令 python manage 运行 Django 时.py runserver
我有错误
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: 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
ModuleNotFoundError: 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?
如果我运行which which python
我可以看到python: aliased to/usr/local/bin/python3.7
这似乎是错误的,因为我期望类似的东西/Users/myuser/Python-Projects/test/venv/bin/python
。事实上,如果我禁用 venv,which python
的结果是相同的。
我尝试使用 bash 执行相同的步骤,一切正常,所以我猜 zsh 出了问题,但我不知道是什么。
作为运行 Django 的解决方法,我必须运行命令 venv/bin/python manage.py runserver
,所以它就像根 python
在某种程度上被破坏了。我尝试将 zsh 更新到最新版本,但问题仍然存在。
有什么想法吗?
最佳答案
发现问题。它是 .zshrc
中 python
的别名。
关于python - 无法在 zsh 中使用事件 venv 运行 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60917220/