我想创建 django 项目,所以我配置了 virtualenv ,并且pipenv install django==4.0.1
在使用此命令创建应用程序时安装了 django,python3 manage.py startapp Accounts
但出现此错误。
(env) zakaria@ZAKARIA:/mnt/c/Users/ZAKARIA/Desktop/project$ python manage.py startapp Accounts
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django.core'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 13, in main
raise ImportError(
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?
任何人都可以帮助解决这个问题吗?
而不是python3 manage.py startapp Accounts
尝试python manage.py startapp Accounts
与您的venv
激活。
为了解释为什么这很重要,让我们做一个练习。在没有venv
激活的情况下开始,请尝试此过程(如果您处于以下状态,则可能需要使用deactivate
命令关闭venv
:
python -m venv my_venv
# The following line assumes you're on Linux or Mac; it appears you're using WSL-2, which is fine
. my_venv/bin/activate
# The following command should show the path to the Python binary in your venv
which python
# The following command may show that you're not hitting the Python version in your venv, but somewhere else
which python3
您要确保您使用的是venv
. 祝你好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句