[英]ModuleNotFoundError: No module named 'django.core'
我想創建 django 項目,所以我配置了 virtualenv,我安裝了 django pipenv install django==4.0.1
當我使用這個命令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
。
為了解釋為什么這很重要,讓我們 go 通過一個練習。 從沒有激活venv
開始,嘗試這個過程(如果你在venv
中,你可能需要使用deactivate
命令來關閉:
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 中的venv
二進制文件。 祝你好運!
當我將 Django 與 Docker 連接時,我遇到了同樣的問題。我通過運行以下命令解決了這個問題:
docker-compose 創建--構建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.