我在windows上的virtualenv中创建了一个项目,然后尝试运行它,但出现了以下错误:
Traceback (most recent call last):
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagementbase.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagementcommandsrunserver.py", line 60, in execute
super().execute(*args, **options)
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagementbase.py", line 369, in execute
output = self.handle(*args, **options)
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagementcommandsrunserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 76, in __getattr__
self._setup(name)
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:Python39libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C:\Python39\Lib\site-packages\django\conf'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:WindowsSystem32djangodjango_projectmanage.py", line 21, in <module>
main()
File "C:WindowsSystem32djangodjango_projectmanage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagement__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagement__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:WindowsSystem32django.venvlibsite-packagesdjangocoremanagementbase.py", line 341, in run_from_argv
connections.close_all()
File "C:WindowsSystem32django.venvlibsite-packagesdjangodbutils.py", line 225, in close_all
for alias in self:
File "C:WindowsSystem32django.venvlibsite-packagesdjangodbutils.py", line 219, in __iter__
return iter(self.databases)
File "C:WindowsSystem32django.venvlibsite-packagesdjangoutilsfunctional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:WindowsSystem32django.venvlibsite-packagesdjangodbutils.py", line 153, in databases
self._databases = settings.DATABASES
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 76, in __getattr__
self._setup(name)
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "C:WindowsSystem32django.venvlibsite-packagesdjangoconf__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:Python39libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C:\Python39\Lib\site-packages\django\conf'
这是我的应用程序版本
- asgiref 3.2.7
- Django 3.0.5
- pip 20.0.2
- pytz 2019.3
- setuptools 41.2.0
- sqlparse 0.3.1
- 我的文件:
- manage.py
- django_project:
- asgi.py
- 设置.py
- urls.py
- wsgi.py
- init.py
我尝试在项目中构建virtualenv,但仍然无法工作。
请帮帮我:(
-
您必须激活您的虚拟
source ~/your_virtual_env_directory/Scripts/activate
- 在项目目录中运行命令
python manage.py runserver
使用pipenv制作虚拟环境
步骤:
1.(使用终端定位您的项目,比如说cd/desktop/myproject
2.(然后使用以下命令(如果你喜欢,你可以更改django版本(
pipenv install django==3.0.1
然后使用启动虚拟环境
pipenv shell
它将创建你的虚拟环境,比如这样(我的项目($
3.(使用退出虚拟环境
exit
4.(使用再次启动相同的虚拟环境
pipenv shell