我最近尝试重新安装 Python,在成功安装 Python 后,使用激活虚拟环境后,pipenv shell
每当我尝试运行时python manage.py
都会收到以下错误:
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
File "C:\Users\moaha\.virtualenvs\restapi-Ks1Qcdgf\lib\site-packages\django\__init__.py", line 1, in <module>
from django.utils.version import get_version
File "C:\Users\moaha\.virtualenvs\restapi-Ks1Qcdgf\lib\site-packages\django\utils\version.py", line 1, in <module>
import datetime
ModuleNotFoundError: No module named 'datetime'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 16, in main
) from exc
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?
Python 本身运行良好,并且pipenv
也能正常工作(正确激活环境),并且我尝试在pip
和上运行更新pipenv
。我不太清楚发生了什么以及如何解决这个问题。
以下是我的环境变量>路径的样子:
C:\Program Files (x86)\Python37-32\Scripts\
C:\Program Files (x86)\Python37-32\
另外,有时我会收到runpy
错误,不确定这是否与此有关。但是,我无法复制该runpy
问题。
我真诚地感谢任何帮助。谢谢!
答案1
我能够“解决”(我猜这更像是一份黑客工作?)这个问题,通过进入.virtualenvs
位于的文件夹C:\Users\<user>\.virtualenvs
,删除所有存在该问题的项目文件夹,然后使用> pipenv shell
后跟的> pipenv install
来安装所有依赖项。