语法错误:生成器表达式必须用括号括起来 / python manage.py migrate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48822571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:52:12  来源:igfitidea点击:

SyntaxError: Generator expression must be parenthezised / python manage.py migrate

pythondjangosyntax-errormigrate

提问by julo6

I'm really new in programming and I wanted to follow the Djangogirls tutorial, but I'm stucked now. In the tutorial, I am here:

我真的是编程新手,我想学习 Djangogirls 教程,但我现在被困住了。在教程中,我在这里

To create a database for our blog, let's run the following in the console: python manage.py migrate (we need to be in the djangogirls directory that contains the manage.py file). If that goes well, you should see something like this: ...

要为我们的博客创建数据库,让我们在控制台中运行以下命令: python manage.py migrate (我们需要在包含 manage.py 文件的 djangogirls 目录中)。如果一切顺利,您应该会看到如下内容:...

There is no option to fail in the tutorial but I have an error message:

教程中没有失败的选项,但我有一条错误消息:

(myvenv) C:\Users\Julcsi\djangogirls> python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\core\management\__init__.py", 
line 364, in execute_from_command_line
utility.execute()
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\core\management\__init__.py", 
line 338, in execute
django.setup()
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\__init__.py", 
line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\apps\registry.py", 
line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\apps\config.py", 
line 94, in create
module = import_module(entry)
File "C:\Users\Julcsi\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 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 723, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_remove
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\__init__.py", 
line 4, in <module>
from django.contrib.admin.filters import (
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\filters.py", 
line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "C:\Users\Julcsi\djangogirls\myvenv\lib\site-packages\django\contrib\admin\options.py", 
line 12, in <module>
from django.contrib.admin import helpers, widgets
File "C:\Users\Julcsi\djangogirls\myvenv\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

What am I doing wrong? What should I do?

我究竟做错了什么?我该怎么办?

I have Python 3.7.0b1

我有 Python 3.7.0b1

Thanks a lot in advance for the help :)

非常感谢您的帮助:)

回答by Ry-

You're not doing anything wrong; this is a problem between Django and Python 3.7. Django has a fix, but that fix hasn't made it into a new version yet.

你没有做错任何事;这是 Django 和 Python 3.7 之间的问题。Django 有一个修复程序,但该修复程序尚未进入新版本。

You can install the stable version of Python, Python 3.6, in the meantime.

您可以同时安装 Python 的稳定版本 Python 3.6。

回答by Antwane

This is a known incompatibilitybetween Django and Python 3.7. A fix has already been merged into Django 2.x branchesand backported into 1.11 branch.

这是Django 和 Python 3.7 之间已知的不兼容。一个修复程序已经被合并到 Django 2.x 分支并被反向移植到1.11 分支

To solve this issue, simply update Django to at least version 1.11.17 (or 2.x)or you can downgrade Python to version 3.6.

要解决此问题,只需将 Django 更新到至少1.11.17(或 2.x)版本,或者您可以将 Python 降级到版本 3.6。

回答by Chiharu Miyoshi

Also, upgrading Django solved my problem

另外,升级 Django 解决了我的问题

On your terminal,

在您的终端上,

$ pip install -U Django

or see here

或看这里

回答by das-g

The Django Girls tutorial version in Englishhas just switched to Django 2.0which should make it compatible to Python 3.7. (Django 2.0 includes a backportof the fix mentioned in Ry-'s answer.)

英语Django的女孩教程版本只是切换到Django的2.0应该使它对Python 3.7兼容。(Django 2.0 包含Ry-的回答中提到的修复程序的反向移植。)

So everyone beginning the tutorial now should be fine with Python 3.7.

所以现在开始学习本教程的每个人都应该可以使用 Python 3.7。

If you've already begun the tutorial you'd have to start again at the Django installationchapter. You'll want to do that in a new directory (either delete or rename your current djangogirlsdirectory or choose a different name for the new directory) as the files generated by

如果您已经开始本教程,则必须从Django 安装章节重新开始。您需要在新目录中执行此操作(删除或重命名当前djangogirls目录或为新目录选择不同的名称)作为由

django-admin print startproject mysite .

depend on the Django version in use.

取决于使用的 Django 版本。

回答by Tim Graham

Per Django's FAQ, Django 1.11.x is not compatible with Python 3.7.

根据Django 的 FAQ,Django 1.11.x 与 Python 3.7 不兼容。

Django 1.11.x reached end of mainstream supporton December 2, 2017 and it receives only data loss and security fixes until its end of life.

Django 1.11.x于 2017 年 12 月 2 日终止了主流支持,在其生命周期结束前仅收到数据丢失和安全修复。

回答by Rakesh Paruchuri

Only Django==2.2 will be supported to Python 3.7 so upgrading your Django Version will solve your problem

Python 3.7 仅支持 Django==2.2,因此升级您的 Django 版本将解决您的问题

pip3 install django --upgrade

回答by Akash Giri

As all of the above answers already suggesting that there's a miss match between Django and Python version.
While creating a virtual environment, please run the following command

由于上述所有答案已经表明 Django 和 Python 版本之间存在不匹配。
创建虚拟环境时,请运行以下命令

python3.6 -m venv myenv

It will use Python3.6while creating your virtual environment.
Now you can install all the dependencies in this virtual environment.

它将在创建您的虚拟环境时使用Python3.6
现在您可以在此虚拟环境中安装所有依赖项。