django v1.x版本 启动错误:SyntaxError: Generator expression must be parenthesized

django v1.x版本 启动错误:SyntaxError: Generator expression must be parenthesized

 

报错信息

Failed to get real commands on module "mysite": python process died with code 1: Traceback (most recent call last):
  File "E:\JetBrains\PyCharm 2020.1\plugins\python\helpers\pycharm\_jb_manage_tasks_provider.py", line 25, in <module>
    django.setup()
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\apps\config.py", line 94, in create
    module = import_module(entry)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\contrib\admin\__init__.py", line 4, in <module>
    from django.contrib.admin.filters import (
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\contrib\admin\filters.py", line 10, in <module>
    from django.contrib.admin.options import IncorrectLookupParameters
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\contrib\admin\options.py", line 12, in <module>
    from django.contrib.admin import helpers, widgets
  File "E:\PycharmProjects\python\venv\lib\site-packages\django\contrib\admin\widgets.py", line 152
    '%s=%s' % (k, v) for k, v in params.items(),
    ^
SyntaxError: Generator expression must be parenthesized

 

 

报错原因

  django v1.11版本和python 3.7版本不兼容导致的,2.0版本以后的django修复了此问题

 

 

解决方法

  方法1:找到python解释器对应的报错文件路径下的widgets.py,将逗号删除即可(我使用的是虚拟环境)

  方法2:升级django版本(不建议使用新版本)

pip install -U Django
posted @ 2020-12-04 17:06  chchcharlie、  阅读(237)  评论(0编辑  收藏  举报