python - 无法在 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 更新到最新版本,但问题仍然存在。
有任何想法吗?
解决方案
发现问题。它是python
in的别名.zshrc
。
推荐阅读
- reactjs - 警告:道具类型失败:提供给“轮播”的“对象”类型的无效道具“数据”,应为“数组”
- python-3.x - 使用 while 和 for 语句迭代 2d numpy 数组
- python - 为什么在conda环境python3.6使用pip命令总是会提示错误?
- sql-server - sql server 2008 和 2016 中“-”的校验和值不同,因此无法比较修改后的数据
- javascript - 当我使用 Three.js 更改 gltf 格式的纹理时,如何将纹理放到正确的位置?
- android - Prolificinteractive Material CalendarView:CurrentDay 设置为星期一时,显示从下个月开始的整周
- html - 在 Angular 的文本框中添加附件文件选项
- django - 无法使用以下类型的值设置 MODEL_NAME SpatialProxy (POLYGON):
- c# - 如何使用我制作的应用程序将图像保存到图库?
- octave - Octave:如何从 Java ResultSet 对象中检索数据?