Docker-compose不再构建镜像(AttributeError: cython_sources)

62
我正在构建一个django-react网站,突然间我的docker-compose不再构建,尽管没有对requirements或镜像版本进行任何更改。
我的requirements.txt文件如下所示:
Django>=3.2.4,<4.0
djangorestframework>=3.12.4,<3.14.0
djangorestframework-simplejwt>=4.8.0,<5.3.0
psycopg2>=2.8.6,<2.9
drf-spectacular>=0.15.1,<0.30
django-allauth>0.5,<1.0
dj-rest-auth>=3.0,<4.0

错误输出:
 => [backend internal] load .dockerignore                                                                                                                                                                  0.0s 
 => => transferring context: 234B                                                                                                                                                                          0.0s 
 => [backend internal] load build definition from Dockerfile                                                                                                                                               0.0s 
 => => transferring dockerfile: 933B                                                                                                                                                                       0.0s 
 => [backend internal] load metadata for docker.io/library/python:3.9-alpine3.13                                                                                                                           0.5s 
 => [backend 1/6] FROM docker.io/library/python:3.9-alpine3.13@sha256:a7cbd1e7784a35a098cedbc8681b790d35ff6030a5e13f043185e2465003a040                                                                     0.0s 
 => [backend internal] load build context                                                                                                                                                                  0.0s 
 => => transferring context: 2.53kB                                                                                                                                                                        0.0s 
 => CACHED [backend 2/6] WORKDIR /app/backend                                                                                                                                                              0.0s 
 => CACHED [backend 3/6] COPY ./requirements.txt /tmp/requirements.txt                                                                                                                                     0.0s 
 => CACHED [backend 4/6] COPY ./requirements.dev.txt /tmp/requirements.dev.txt                                                                                                                             0.0s 
 => CACHED [backend 5/6] COPY . /app/backend                                                                                                                                                               0.0s 
 => ERROR [backend 6/6] RUN python -m venv /py &&     /py/bin/pip install --upgrade pip &&     apk add --update --no-cache postgresql-client jpeg-dev &&     apk add --update --no-cache --virtual .tmp-  18.9s 
------
 > [backend 6/6] RUN python -m venv /py &&     /py/bin/pip install --upgrade pip &&     apk add --update --no-cache postgresql-client jpeg-dev &&     apk add --update --no-cache --virtual .tmp-build-deps     
    build-base postgresql-dev musl-dev zlib zlib-dev &&     /py/bin/pip install -r /tmp/requirements.txt &&     if [ true = "true" ];         then /py/bin/pip install -r /tmp/requirements.dev.txt ;     fi && 
    rm -rf /tmp &&     apk del .tmp-build-deps &&     adduser         --disabled-password         --no-create-home         django-user:
2.951 Requirement already satisfied: pip in /py/lib/python3.9/site-packages (21.2.4)
3.090 Collecting pip
3.202   Downloading pip-23.2-py3-none-any.whl (2.1 MB)
3.389 Installing collected packages: pip
3.389   Attempting uninstall: pip
3.389     Found existing installation: pip 21.2.4
3.454     Uninstalling pip-21.2.4:
3.458       Successfully uninstalled pip-21.2.4
4.339 Successfully installed pip-23.2
4.506 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
4.832 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
5.062 (1/9) Installing libjpeg-turbo (2.1.0-r0)
5.092 (2/9) Installing pkgconf (1.7.3-r0)
5.116 (3/9) Installing libjpeg-turbo-dev (2.1.0-r0)
5.137 (4/9) Installing jpeg-dev (9d-r1)
5.156 (5/9) Installing libedit (20191231.3.1-r1)
5.179 (6/9) Installing libsasl (2.1.28-r0)
5.204 (7/9) Installing libldap (2.4.57-r1)
5.263 (8/9) Installing libpq (13.11-r0)
5.287 (9/9) Installing postgresql-client (13.11-r0)
5.358 Executing busybox-1.32.1-r7.trigger
5.362 OK: 20 MiB in 45 packages
5.383 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
5.520 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
5.644 (1/37) Upgrading musl (1.2.2-r1 -> 1.2.2-r2)
5.676 (2/37) Upgrading libcrypto1.1 (1.1.1l-r0 -> 1.1.1s-r0)
5.755 (3/37) Upgrading libssl1.1 (1.1.1l-r0 -> 1.1.1s-r0)
5.806 (4/37) Upgrading zlib (1.2.11-r3 -> 1.2.12-r3)
5.830 (5/37) Installing libgcc (10.2.1_pre1-r3)
5.860 (6/37) Installing libstdc++ (10.2.1_pre1-r3)
5.923 (7/37) Installing binutils (2.35.2-r1)
6.069 (8/37) Installing libmagic (5.39-r0)
6.137 (9/37) Installing file (5.39-r0)
6.156 (10/37) Installing libgomp (10.2.1_pre1-r3)
6.191 (11/37) Installing libatomic (10.2.1_pre1-r3)
6.208 (12/37) Installing libgphobos (10.2.1_pre1-r3)
6.307 (13/37) Installing gmp (6.2.1-r1)
6.342 (14/37) Installing isl22 (0.22-r0)
6.403 (15/37) Installing mpfr4 (4.1.0-r0)
6.501 (16/37) Installing mpc1 (1.2.0-r0)
6.528 (17/37) Installing gcc (10.2.1_pre1-r3)
7.430 (18/37) Installing musl-dev (1.2.2-r2)
7.544 (19/37) Installing libc-dev (0.7.2-r3)
7.574 (20/37) Installing g++ (10.2.1_pre1-r3)
8.135 (21/37) Installing make (4.3-r0)
8.157 (22/37) Installing fortify-headers (1.1-r0)
8.177 (23/37) Installing patch (2.7.6-r7)
8.209 (24/37) Installing build-base (0.5-r3)
8.229 (25/37) Installing libxml2 (2.9.14-r2)
8.293 (26/37) Installing llvm10-libs (10.0.1-r1)
8.719 (27/37) Installing clang-libs (10.0.1-r0)
9.345 (28/37) Installing clang (10.0.1-r0)
9.587 (29/37) Installing llvm10 (10.0.1-r1)
9.695 (30/37) Installing openssl-dev (1.1.1s-r0)
9.724 (31/37) Installing icu-libs (67.1-r2)
9.985 (32/37) Installing icu (67.1-r2)
10.01 (33/37) Installing icu-dev (67.1-r2)
10.07 (34/37) Installing postgresql-libs (13.11-r0)
10.10 (35/37) Installing postgresql-dev (13.11-r0)
10.22 (36/37) Installing zlib-dev (1.2.12-r3)
10.25 (37/37) Installing .tmp-build-deps (20230717.214226)
10.25 Executing busybox-1.32.1-r7.trigger
10.25 Executing ca-certificates-20191127-r5.trigger
10.31 OK: 414 MiB in 78 packages
10.78 Collecting Django<4.0,>=3.2.4 (from -r /tmp/requirements.txt (line 1))
10.78   Obtaining dependency information for Django<4.0,>=3.2.4 from https://files.pythonhosted.org/packages/84/eb/5329ae72bf26b91844985d0de74e4edf876e3ca409d085820f230eea2eba/Django-3.2.20-py3-none-any.whl.metadata
10.84   Downloading Django-3.2.20-py3-none-any.whl.metadata (4.1 kB)
10.91 Collecting djangorestframework<3.14.0,>=3.12.4 (from -r /tmp/requirements.txt (line 2))
10.93   Downloading djangorestframework-3.13.1-py3-none-any.whl (958 kB)
11.04      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 958.3/958.3 kB 9.6 MB/s eta 0:00:00
11.07 Collecting djangorestframework-simplejwt<5.3.0,>=4.8.0 (from -r /tmp/requirements.txt (line 3))
11.09   Downloading djangorestframework_simplejwt-5.2.2-py3-none-any.whl (85 kB)
11.11      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.4/85.4 kB 7.8 MB/s eta 0:00:00
11.17 Collecting psycopg2<2.9,>=2.8.6 (from -r /tmp/requirements.txt (line 4))
11.19   Downloading psycopg2-2.8.6.tar.gz (383 kB)
11.21      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 383.8/383.8 kB 30.7 MB/s eta 0:00:00
11.24   Installing build dependencies: started
12.43   Installing build dependencies: finished with status 'done'
12.43   Getting requirements to build wheel: started
12.57   Getting requirements to build wheel: finished with status 'done'
12.57   Preparing metadata (pyproject.toml): started
12.69   Preparing metadata (pyproject.toml): finished with status 'done'
12.74 Collecting drf-spectacular<0.30,>=0.15.1 (from -r /tmp/requirements.txt (line 5))
12.74   Obtaining dependency information for drf-spectacular<0.30,>=0.15.1 from https://files.pythonhosted.org/packages/e2/3b/29189bbfb2443335ed1d6f0750d14f7ba5e5b89699a58cc87fa82fdb5f49/drf_spectacular-0.26.3-py3-none-any.whl.metadata
12.76   Downloading drf_spectacular-0.26.3-py3-none-any.whl.metadata (13 kB)
12.79 Collecting django-allauth<1.0,>0.5 (from -r /tmp/requirements.txt (line 6))
12.81   Downloading django-allauth-0.54.0.tar.gz (737 kB)
12.85      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 737.1/737.1 kB 18.6 MB/s eta 0:00:00
13.04   Installing build dependencies: started
14.05   Installing build dependencies: finished with status 'done'
14.05   Getting requirements to build wheel: started
14.24   Getting requirements to build wheel: finished with status 'done'
14.25   Preparing metadata (pyproject.toml): started
14.44   Preparing metadata (pyproject.toml): finished with status 'done'
14.48 Collecting dj-rest-auth<4.0,>=3.0 (from -r /tmp/requirements.txt (line 7))
14.50   Downloading dj-rest-auth-3.0.0.tar.gz (100 kB)
14.51      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.2/100.2 kB 10.6 MB/s eta 0:00:00
14.54   Installing build dependencies: started
15.52   Installing build dependencies: finished with status 'done'
15.52   Getting requirements to build wheel: started
15.63   Getting requirements to build wheel: finished with status 'done'
15.63   Preparing metadata (pyproject.toml): started
15.75   Preparing metadata (pyproject.toml): finished with status 'done'
15.79 Collecting asgiref<4,>=3.3.2 (from Django<4.0,>=3.2.4->-r /tmp/requirements.txt (line 1))
15.79   Obtaining dependency information for asgiref<4,>=3.3.2 from https://files.pythonhosted.org/packages/9b/80/b9051a4a07ad231558fcd8ffc89232711b4e618c15cb7a392a17384bbeef/asgiref-3.7.2-py3-none-any.whl.metadata
15.80   Downloading asgiref-3.7.2-py3-none-any.whl.metadata (9.2 kB)
15.87 Collecting pytz (from Django<4.0,>=3.2.4->-r /tmp/requirements.txt (line 1))
15.90   Downloading pytz-2023.3-py2.py3-none-any.whl (502 kB)
15.93      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.3/502.3 kB 20.1 MB/s eta 0:00:00
15.96 Collecting sqlparse>=0.2.2 (from Django<4.0,>=3.2.4->-r /tmp/requirements.txt (line 1))
15.98   Downloading sqlparse-0.4.4-py3-none-any.whl (41 kB)
15.99      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.2/41.2 kB 11.2 MB/s eta 0:00:00
16.05 Collecting pyjwt<3,>=1.7.1 (from djangorestframework-simplejwt<5.3.0,>=4.8.0->-r /tmp/requirements.txt (line 3))
16.07   Downloading PyJWT-2.7.0-py3-none-any.whl (22 kB)
16.11 Collecting uritemplate>=2.0.0 (from drf-spectacular<0.30,>=0.15.1->-r /tmp/requirements.txt (line 5))
16.13   Downloading uritemplate-4.1.1-py2.py3-none-any.whl (10 kB)
16.18 Collecting PyYAML>=5.1 (from drf-spectacular<0.30,>=0.15.1->-r /tmp/requirements.txt (line 5))
16.20   Downloading PyYAML-6.0.tar.gz (124 kB)
16.21      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 125.0/125.0 kB 16.8 MB/s eta 0:00:00
16.31   Installing build dependencies: started
18.33   Installing build dependencies: finished with status 'done'
18.33   Getting requirements to build wheel: started
18.48   Getting requirements to build wheel: finished with status 'error'
18.48   error: subprocess-exited-with-error
18.48
18.48   × Getting requirements to build wheel did not run successfully.
18.48   │ exit code: 1
18.48   ╰─> [48 lines of output]
18.48       running egg_info
18.48       writing lib/PyYAML.egg-info/PKG-INFO
18.48       writing dependency_links to lib/PyYAML.egg-info/dependency_links.txt
18.48       writing top-level names to lib/PyYAML.egg-info/top_level.txt
18.48       Traceback (most recent call last):
18.48         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
18.48           main()
18.48         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
18.48           json_out['return_val'] = hook(**hook_input['kwargs'])
18.48         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
18.48           return hook(config_settings)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
18.48           return self._get_build_requires(config_settings, requirements=['wheel'])
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
18.48           self.run_setup()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 338, in run_setup
18.48           exec(code, locals())
18.48         File "<string>", line 288, in <module>
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 107, in setup
18.48           return distutils.core.setup(**attrs)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
18.48           return run_commands(dist)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
18.48           dist.run_commands()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
18.48           self.run_command(cmd)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 1234, in run_command
18.48           super().run_command(command)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
18.48           cmd_obj.run()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 314, in run
18.48           self.find_sources()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 322, in find_sources
18.48           mm.run()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 551, in run
18.48           self.add_defaults()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 589, in add_defaults
18.48           sdist.add_defaults(self)
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/command/sdist.py", line 104, in add_defaults
18.48           super().add_defaults()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults
18.48           self._add_defaults_ext()
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 336, in _add_defaults_ext
18.48           self.filelist.extend(build_ext.get_source_files())
18.48         File "<string>", line 204, in get_source_files
18.48         File "/tmp/pip-build-env-a_iltcrr/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__
18.48           raise AttributeError(attr)
18.48       AttributeError: cython_sources
18.48       [end of output]
18.48
18.48   note: This error originates from a subprocess, and is likely not a problem with pip.
18.49 error: subprocess-exited-with-error
18.49
18.49 × Getting requirements to build wheel did not run successfully.
18.49 │ exit code: 1
18.49 ╰─> See above for output.
18.49
18.49 note: This error originates from a subprocess, and is likely not a problem with pip.

我昨天使用这些依赖项构建了完全相同的镜像,所以我知道它是兼容的。然而,今天尝试构建却不再起作用。
根据Simeon Borisov的答案,问题似乎出在我的requirements文件夹中的drf-spectacular,删除它可以解决构建问题。
然而,我仍然在努力解决。
1. 在它上面添加pyyaml==5.4.1并不能解决问题。 2. 这很奇怪,因为在这些确切的版本之前它们可以一起工作,但现在却不能。此外,我在最初学习Docker时看到的一些教程中编译的旧版本,我自己也用过,现在也不再适用于我。到底发生了什么变化?
在添加pyyaml依赖后,我的错误日志如下:
Collecting Django<4.0,>=3.2.4 (from -r /tmp/requirements.txt (line 1))
23.17   Obtaining dependency information for Django<4.0,>=3.2.4 from https://files.pythonhosted.org/packages/84/eb/5329ae72bf26b91844985d0de74e4edf876e3ca409d085820f230eea2eba/Django-3.2.20-py3-none-any.whl.metadata
23.32   Downloading Django-3.2.20-py3-none-any.whl.metadata (4.1 kB)
23.37 Collecting djangorestframework<3.14.0,>=3.12.4 (from -r /tmp/requirements.txt (line 2))
23.39   Downloading djangorestframework-3.13.1-py3-none-any.whl (958 kB)
23.54      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 958.3/958.3 kB 6.8 MB/s eta 0:00:00
23.57 Collecting djangorestframework-simplejwt<5.3.0,>=4.8.0 (from -r /tmp/requirements.txt (line 3))
23.60   Downloading djangorestframework_simplejwt-5.2.2-py3-none-any.whl (85 kB)
23.61      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.4/85.4 kB 9.6 MB/s eta 0:00:00
23.68 Collecting psycopg2<2.9,>=2.8.6 (from -r /tmp/requirements.txt (line 4))
23.71   Downloading psycopg2-2.8.6.tar.gz (383 kB)
23.76      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 383.8/383.8 kB 7.9 MB/s eta 0:00:00
23.80   Installing build dependencies: started
25.10   Installing build dependencies: finished with status 'done'
25.10   Getting requirements to build wheel: started
25.23   Getting requirements to build wheel: finished with status 'done'
25.23   Preparing metadata (pyproject.toml): started
25.36   Preparing metadata (pyproject.toml): finished with status 'done'
25.46 Collecting pyyaml==5.4.1 (from -r /tmp/requirements.txt (line 5))
25.48   Downloading PyYAML-5.4.1.tar.gz (175 kB)
25.50      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 175.1/175.1 kB 7.7 MB/s eta 0:00:00
25.60   Installing build dependencies: started
27.95   Installing build dependencies: finished with status 'done'
27.95   Getting requirements to build wheel: started
28.12   Getting requirements to build wheel: finished with status 'error'
28.12   error: subprocess-exited-with-error
28.12
28.12   × Getting requirements to build wheel did not run successfully.
28.12   │ exit code: 1
28.12   ╰─> [62 lines of output]
28.12       /tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/config/setupcfg.py:293: _DeprecatedConfig: Deprecated config in `setup.cfg`
28.12       !!
28.12
28.12               ********************************************************************************
28.12               The license_file parameter is deprecated, use license_files instead.
28.12
28.12               By 2023-Oct-30, you need to update your project and remove deprecated calls
28.12               or your builds will no longer be supported.
28.12
28.12               See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
28.12               ********************************************************************************
28.12
28.12       !!
28.12         parsed = self.parsers.get(option_name, lambda x: x)(value)
28.12       running egg_info
28.12       writing lib3/PyYAML.egg-info/PKG-INFO
28.12       writing dependency_links to lib3/PyYAML.egg-info/dependency_links.txt
28.12       writing top-level names to lib3/PyYAML.egg-info/top_level.txt
28.12       Traceback (most recent call last):
28.12         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
28.12           main()
28.12         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
28.12           json_out['return_val'] = hook(**hook_input['kwargs'])
28.12         File "/py/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
28.12           return hook(config_settings)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
28.12           return self._get_build_requires(config_settings, requirements=['wheel'])
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
28.12           self.run_setup()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 338, in run_setup
28.12           exec(code, locals())
28.12         File "<string>", line 271, in <module>
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 107, in setup
28.12           return distutils.core.setup(**attrs)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
28.12           return run_commands(dist)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
28.12           dist.run_commands()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
28.12           self.run_command(cmd)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 1234, in run_command
28.12           super().run_command(command)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
28.12           cmd_obj.run()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 314, in run
28.12           self.find_sources()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 322, in find_sources
28.12           mm.run()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 551, in run
28.12           self.add_defaults()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 589, in add_defaults
28.12           sdist.add_defaults(self)
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/command/sdist.py", line 104, in add_defaults
28.12           super().add_defaults()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults
28.12           self._add_defaults_ext()
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/sdist.py", line 336, in _add_defaults_ext
28.12           self.filelist.extend(build_ext.get_source_files())
28.12         File "<string>", line 201, in get_source_files
28.12         File "/tmp/pip-build-env-m9dhhrb5/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__
28.12           raise AttributeError(attr)
28.12       AttributeError: cython_sources
28.12       [end of output]
28.12
28.12   note: This error originates from a subprocess, and is likely not a problem with pip.
28.13 error: subprocess-exited-with-error
28.13
28.13 × Getting requirements to build wheel did not run successfully.
28.13 │ exit code: 1
28.13 ╰─> See above for output.

如果您的问题与awscli有关,这是在github上的问题链接:https://github.com/aws/aws-cli/issues/8036 - Math M.
如果您的问题与awscli有关,这是在GitHub上的问题链接:https://github.com/aws/aws-cli/issues/8036 - Math M.
从问题中移开,因为答案不属于那里。我相信这是由OP写的:在Simeon的建议下,我找到了确切的问题。问题不仅仅出在drf上,还与pyyaml依赖有关。这是由于一个更新导致的,所以最近的(根据此帖子发布的时间)5.4.1版本本身就有问题。我相信是Cython的更新导致了这个问题。GitHub的问题可以在这里找到:https://github.com/yaml/pyyaml/issues/724解决方案如下所述,在那里发布的是安装pyyaml并临时降级到5.3.1版本。 - undefined
如果你愿意的话,你可以将那段文字移到一个独立的回答中,这样阅读起来会更容易,因为在评论中它的格式会变得很丑。 - undefined
对于Python 3.12用户,请访问https://stackoverflow.com/questions/77490435/attributeerror-cython-sources - undefined
9个回答

59

重要的安全免责声明:我强烈不建议任何人将PyYAML降级到5.3.1版本,因为5.4之前的所有版本都存在已知CVE - CVE-2020-14343


这个问题是由于在Cython>=3.0版本下编译的PyYAML<6.0.1存在不兼容性引起的,此版本于2023年7月17日发布。

现在这个问题已经通过PyYAML的新发布版本,标记为6.0.1进行修复。

这个发布版本带来了:

没有代码更改;更新PEP518构建元数据以要求Cython < 3.0,直到为Cython 3.0兼容性重写打包代码。

正如可以在此项目公告中阅读到的。

所以,只要您没有将PyYAML严格固定到特定版本,这似乎是您在需求文件中的情况,那么一切都会再次正常工作。
如果您的库限制为PyYAML<6.0,修复方法是使用标志--no-build-isolation安装该库。
python -m pip install --no-build-isolation \
  <problematic-library-depending-on-old-verion-of-PyYAML>

在我的情况下没有解决这个问题:/ - anion
在我的情况下没有解决问题 :/ - anion
你能确定是哪个依赖项导致了这个问题吗? - β.εηοιτ.βε
你能确定导致这个问题的依赖关系吗? - β.εηοιτ.βε
这绝对与这个问题开始出现的时间相吻合。我的要求现在在这次更新之后安装完成。 - wsams
显示剩余2条评论

12
更新到pyyaml==6.0.1对我有所帮助。

11

基本上,问题是由Cython 3.0.0的新版本引起的。

在我的情况下,问题出现在awscli上。通过在我的awscli安装之前添加这行代码,解决了我的问题。

这种方法的好处还在于您不需要回退到易受攻击的pyyaml 5.3.1版本。

pip install "cython<3.0.0" wheel && pip install pyyaml==5.4.1 --no-build-isolation
pip install awscli

编辑:使用 awscli >= 1.29.4 版本,您现在可以使用 pyyaml 6.0.1 并解决这个问题。

pip install pyyaml~=6.0
pip install awscli

5
根据this线程,这似乎是一个回归问题。PyYAML包可能是您的某个依赖项的依赖项,并自动更新到了一个损坏的版本(很可能是因为drf-spectacular)。您应该能够将pyyaml包添加到您的requirements.txt文件中,并指定其版本。也许您还应该在drf-spectacular的版本控制上更加具体,以防出现依赖兼容性问题。
pyyaml==5.4.1
drf-spectacular=={whatever the version was yesterday}

如果您希望将来避免这种情况,考虑使用pipenv及其Pipfile和Pipfile.lock版本控制系统,它可以让您对构建中使用的版本进行控制。
编辑:我从其他帖子中看到问题已经解决,更新pyyaml到最新版本可能是个好主意。

非常感谢您的帮助。我认为您说得对,drf 就是问题所在。此外,在 drf 安装时收集 PyYAML>=5.1 的地方出现了 bug。然而,您提到的自然解决方法安装 pyyaml 也出现了问题。我已经将相应的错误代码块添加到我的原始问题中。 - Marco Sousa
也许尝试将Cython版本设置为Cython&lt;3.0。你可以利用一个constraints.txt文件(https://luminousmen.com/post/pip-constraints-files)来具体设置版本,而无需显式安装该软件包本身。 - Simeon Borisov
是的,错误似乎主要出现在Cython和PyYAML依赖之间。为了解决与DRF相关的问题,我将PyYAML降级到了5.3.1版本。非常感谢您的帮助。 - Marco Sousa
2
是的,错误似乎主要出现在Cython和PyYAML依赖之间。为了解决与DRF相关的问题,我将PyYAML降级到了5.3.1版本。非常感谢您的帮助。 - Marco Sousa
@MarcoSousa 5.3.1存在一个安全关键漏洞,这就是为什么我们需要升级它的原因。 - user9920500
显示剩余2条评论

2
降级到pyyaml==5.3.1对我来说起作用了,由于项目中存在依赖冲突,无法升级到最新版本。

1

从pip安装docker-compose不再受支持,对于您的情况,更好的解决方法是升级到compose v2(请参阅https://hub.docker.com/r/docker/compose)。 - undefined

1
正如β.εηοιτ.βε所指出的,这个错误是由于PyYAML<6.0.1Cython>=3.0版本不兼容所致,这个问题在后续的PyYAML版本中已经修复。
然而,在我的requirements.txt文件中,我并没有将PyYAML列为依赖项。所以,PyYAML显然是我的某个依赖项的依赖项...但是是哪一个呢?
为了找出答案,我只需将PyYAML==6.0.1添加到我的requirements.txt文件中。当我运行pip install -r requirements.txt时,控制台输出了一个有用的错误信息:
ERROR: Cannot install -r requirements.txt (line 1) and PyYAML==6.0.1 because these package versions have conflicting dependencies.
The conflict is caused by:
    The user requested PyYAML==6.0.1
    example_dependency 31.0.0 depends on PyYAML<6.0 and >=5.1

有了这个信息,我将example_dependency升级到最新版本,问题得到解决。

0

将版本更改为PyYAML~=6.0以便获取最新的与6.0兼容的发布版。


0
Docker Compose现在(2023年)是作为docker的子命令包含的Golang二进制文件,通过docker compose ...调用。
如果由于某种原因您只想要docker-compose,可以从https://docs.docker.com/compose/install/standalone/下载预编译的Windows和Linux版本。
对于x64架构的Linux系统,当前(v2.23)的直接下载链接如下:
 curl -SL https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接