执行“ Python manage.py runserver”时,Django Runserver错误

时间:2020-01-19 09:15:30

标签: python django

C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\Scripts\FirstDjango
Proj>python manage.py runserver
Exception ignored in thread started by: <function check_errors.<locals>.wrapper
at 0x00000000038D00D0>
Traceback (most recent call last):
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\core\management\commands\runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\apps\config.py", line 94, in create
    module = import_module(entry)
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\importl
ib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\__init__.py", line 4, in <module>
    from django.contrib.admin.filters import (
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\filters.py", line 10, in <module>
    from django.contrib.admin.options import IncorrectLookupParameters
  File "C:\Users\SRIRAM_CHIVO\AppData\Local\Programs\Python\Python38\lib\site-pa
ckages\django\contrib\admin\options.py", line 12, in <module>
    from django.contrib.admin import helpers, widgets
SyntaxError: Generator expression must be parenthesized (widgets.py, line 152)

已成功安装Django版本1.11.10 python版本3.8.1

项目已创建,manage.py也已创建。

当我尝试运行服务器时,用这个大段落抛出错误: 帮我解决该怎么办?

1 个答案:

答案 0 :(得分:0)

我也遇到了同样的情况,但是这个问题是一个小问题,因为如果系统上有多个Python版本,则可以通过运行python3来选择特定的Python版本,也可以选择任意一个版本。因此,您应该从头开始,首先卸载Django,然后创建一个虚拟环境,确定要放置目录的目录,然后运行venv模块作为带有目录路径的脚本:

python3 -m venv tutorial-env

这将创建tutorial-env目录(如果该目录不存在),并在其中创建目录。创建虚拟环境后,可以将其激活。

在Windows上,运行:

tutorial-env\Scripts\activate.bat

在Unix或MacOS上,运行:

source tutorial-env/bin/activate

现在,在命令提示符下,确保您的虚拟环境处于活动状态,并执行以下命令:

py -m pip install Django

注意::如果django-admin仅显示帮助文本,而不管给出了什么参数,则Windows中的文件关联可能存在问题。检查是否在PATH中设置了多个环境变量来运行Python脚本。当安装了多个Python版本时,通常会发生这种情况。