首页 > 解决方案 > 无法在 zsh 中使用活动 venv 运行 Django

问题描述

我在 zsh 中有一个正确激活的 venv,因为我可以(venv)在提示符的开头看到,但是当我尝试使用命令运行 Django 时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
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?

如果我运行 whichwhich python我可以看到python: aliased to /usr/local/bin/python3.7它似乎是错误的,因为我期待类似/Users/myuser/Python-Projects/test/venv/bin/python. 事实上,如果我禁用 venv 的结果which python是一样的。

我尝试使用 bash 执行相同的步骤并且一切正常,所以我想我的 zsh 有问题,但我不知道是什么。

作为运行 Django 的一种解决方法,我必须运行 command venv/bin/python manage.py runserver,所以它就像 rootpython在某种程度上被破坏了。我尝试将 zsh 更新到最新版本,但问题仍然存在。

有任何想法吗?

标签: pythondjangozshpython-venv

解决方案


发现问题。它是pythonin的别名.zshrc


推荐阅读