使用python 3.7的Docker错误:必须将生成器表达式括起来

时间:2018-09-09 00:13:34

标签: django docker

嗨,我正在按照..的django教程(Quickstart: Compose and Django)进行操作,并且出现此错误:

SyntaxError: Generator expression must be parenthesized

回溯

root@localhost:~# docker-compose up
Starting root_db_1 ... done
Starting root_web_1 ... done
Attaching to root_db_1, root_web_1
db_1   | 2018-09-09 00:09:10.440 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2018-09-09 00:09:10.440 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2018-09-09 00:09:10.442 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2018-09-09 00:09:10.481 UTC [21] LOG:  database system was interrupted; last known up at 2018-09-09 00:06:36 UTC
db_1   | 2018-09-09 00:09:10.597 UTC [21] LOG:  database system was not properly shut down; automatic recovery in progress
db_1   | 2018-09-09 00:09:10.599 UTC [21] LOG:  redo starts at 0/1633C88
db_1   | 2018-09-09 00:09:10.599 UTC [21] LOG:  invalid record length at 0/1633CC0: wanted 24, got 0
db_1   | 2018-09-09 00:09:10.599 UTC [21] LOG:  redo done at 0/1633C88
db_1   | 2018-09-09 00:09:10.632 UTC [1] LOG:  database system is ready to accept connections
web_1  | Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f652d99d510>
web_1  | Traceback (most recent call last):
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
web_1  |     fn(*args, **kwargs)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
web_1  |     autoreload.raise_last_exception()
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
web_1  |     six.reraise(*_exception)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/utils/six.py", line 685, in reraise
web_1  |     raise value.with_traceback(tb)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
web_1  |     fn(*args, **kwargs)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 27, in setup
web_1  |     apps.populate(settings.INSTALLED_APPS)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 85, in populate
web_1  |     app_config = AppConfig.create(entry)
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 94, in create
web_1  |     module = import_module(entry)
web_1  |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
web_1  |     return _bootstrap._gcd_import(name[level:], package, level)
web_1  |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
web_1  |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
web_1  |   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
web_1  |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
web_1  |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
web_1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/__init__.py", line 4, in <module>
web_1  |     from django.contrib.admin.filters import (
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/filters.py", line 10, in <module>
web_1  |     from django.contrib.admin.options import IncorrectLookupParameters
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/options.py", line 13, in <module>
web_1  |     from django.contrib.admin import helpers, widgets
web_1  |   File "/usr/local/lib/python3.7/site-packages/django/contrib/admin/widgets.py", line 152
web_1  |     '%s=%s' % (k, v) for k, v in params.items(),
web_1  |     ^
web_1  | SyntaxError: Generator expression must be parenthesized
^CGracefully stopping... (press Ctrl+C again to force)
Stopping root_web_1 ... 
Stopping root_db_1  ... 
Killing root_web_1  ... done
Killing root_db_1   ... done

Dockerfile

 FROM python:3
 ENV PYTHONUNBUFFERED 1
 RUN mkdir /code
 WORKDIR /code
 ADD requirements.txt /code/
 RUN pip install -r requirements.txt
 ADD . /code/

docker-compose.yml

version: '3'

services:
  db:
    image: postgres
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

2 个答案:

答案 0 :(得分:8)

第一个sudo service docker restart

在您的Dockerfile中

FROM python:3.6 

然后sudo docker-compose up --build

sudo docker-compose run web python manage.py migratesudo docker-compose up --build

答案 1 :(得分:3)

在requirements.txt文件中将Django版本从Django> = 1.8,<2.0升级到Django == 2.1.1 通过“ docker-compose up --build”通过重建运行映像,它将解决您的问题。