错误:无法为 psycopg2 构建轮子,这是安装基于 pyproject.toml 的项目所必需的(在通过 render 部署 django 期间)

Umg*_*gee 11 render django-rest-framework python-poetry

我正在尝试通过渲染服务部署我的 python django Rest 框架代码

\n

这是我的 GitHub 代码: https: //github.com/aza1200/stlib-api

\n

这里我使用\npython版本:3.9.10
\nDjango版本:4.0
\n诗歌版本:1.2.2
\ndjangorestfrmaework:3.14.0
\npsycopg2 =“^2.9.5”
\npsycopg2-binary =“^2.9.5”

\n

我在下面收到了消息。

\n
Dec 8 07:20:11 PM    EnvCommandError\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM    Command [\'/opt/render/project/src/.venv/bin/pip\', \'install\', \'--no-deps\', \'/opt/render/.cache/.python-poetry/cache/artifacts/77/61/85/97cbac6c92f7c877efbd9c5c3c38e2bbcb447e3f416742c8ffc1b2b2ec/psycopg2-2.9.5.tar.gz\'] errored with the following return code 1, and output:\nDec 8 07:20:11 PM    Processing /opt/render/.cache/.python-poetry/cache/artifacts/77/61/85/97cbac6c92f7c877efbd9c5c3c38e2bbcb447e3f416742c8ffc1b2b2ec/psycopg2-2.9.5.tar.gz\nDec 8 07:20:11 PM      Installing build dependencies: started\nDec 8 07:20:11 PM      Installing build dependencies: finished with status \'done\'\nDec 8 07:20:11 PM      Getting requirements to build wheel: started\nDec 8 07:20:11 PM      Getting requirements to build wheel: finished with status \'done\'\nDec 8 07:20:11 PM      Preparing metadata (pyproject.toml): started\nDec 8 07:20:11 PM      Preparing metadata (pyproject.toml): finished with status \'done\'\nDec 8 07:20:11 PM    Building wheels for collected packages: psycopg2\nDec 8 07:20:11 PM      Building wheel for psycopg2 (pyproject.toml): started\nDec 8 07:20:11 PM      Building wheel for psycopg2 (pyproject.toml): finished with status \'error\'\nDec 8 07:20:11 PM      error: subprocess-exited-with-error\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM      \xc3\x97 Building wheel for psycopg2 (pyproject.toml) did not run successfully.\nDec 8 07:20:11 PM      \xe2\x94\x82 exit code: 1\nDec 8 07:20:11 PM      \xe2\x95\xb0\xe2\x94\x80> [40 lines of output]\nDec 8 07:20:11 PM          /tmp/pip-build-env-9rm8i7ap/overlay/lib/python3.9/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.\nDec 8 07:20:11 PM            warnings.warn(msg, warning_class)\nDec 8 07:20:11 PM          running bdist_wheel\nDec 8 07:20:11 PM          running build\nDec 8 07:20:11 PM          running build_py\nDec 8 07:20:11 PM          creating build\nDec 8 07:20:11 PM          creating build/lib.linux-x86_64-cpython-39\nDec 8 07:20:11 PM          creating build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/_range.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/errorcodes.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/pool.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/extras.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/__init__.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/sql.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/extensions.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/errors.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/_ipaddress.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/tz.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          copying lib/_json.py -> build/lib.linux-x86_64-cpython-39/psycopg2\nDec 8 07:20:11 PM          running build_ext\nDec 8 07:20:11 PM          building \'psycopg2._psycopg\' extension\nDec 8 07:20:11 PM          creating build/temp.linux-x86_64-cpython-39\nDec 8 07:20:11 PM          creating build/temp.linux-x86_64-cpython-39/psycopg\nDec 8 07:20:11 PM          gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC "-DPSYCOPG_VERSION=2.9.5 (dt dec pq3 ext lo64)" -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140004 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/opt/render/project/src/.venv/include -I/opt/python-installer/Python-3.9.10/include/python3.9 -I. -I/usr/include/postgresql -I/usr/include/postgresql/14/server -I/usr/include/libxml2 -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-cpython-39/psycopg/adapter_asis.o -Wdeclaration-after-statement\nDec 8 07:20:11 PM          In file included from psycopg/adapter_asis.c:28:\nDec 8 07:20:11 PM          ./psycopg/psycopg.h:35:10: fatal error: Python.h: No such file or directory\nDec 8 07:20:11 PM           #include <Python.h>\nDec 8 07:20:11 PM                    ^~~~~~~~~~\nDec 8 07:20:11 PM          compilation terminated.\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM          It appears you are missing some prerequisite to build the package from source.\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM          You may install a binary package by installing \'psycopg2-binary\' from PyPI.\nDec 8 07:20:11 PM          If you want to install psycopg2 from source, please install the packages\nDec 8 07:20:11 PM          required for the build and try again.\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM          For further information please check the \'doc/src/install.rst\' file (also at\nDec 8 07:20:11 PM          <https://www.psycopg.org/docs/install.html>).\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM          error: command \'/usr/bin/gcc\' failed with exit code 1\nDec 8 07:20:11 PM          [end of output]\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM      note: This error originates from a subprocess, and is likely not a problem with pip.\nDec 8 07:20:11 PM      ERROR: Failed building wheel for psycopg2\nDec 8 07:20:11 PM    Failed to build psycopg2\nDec 8 07:20:11 PM    ERROR: Could not build wheels for psycopg2, which is required to install pyproject.toml-based projects\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM    at /home/render/.python-poetry/venv/lib/python3.7/site-packages/poetry/utils/env.py:1195 in _run\nDec 8 07:20:11 PM        1191\xe2\x94\x82                 output = subprocess.check_output(\nDec 8 07:20:11 PM        1192\xe2\x94\x82                     cmd, stderr=subprocess.STDOUT, **kwargs\nDec 8 07:20:11 PM        1193\xe2\x94\x82                 )\nDec 8 07:20:11 PM        1194\xe2\x94\x82         except CalledProcessError as e:\nDec 8 07:20:11 PM      \xe2\x86\x92 1195\xe2\x94\x82             raise EnvCommandError(e, input=input_)\nDec 8 07:20:11 PM        1196\xe2\x94\x82\nDec 8 07:20:11 PM        1197\xe2\x94\x82         return decode(output)\nDec 8 07:20:11 PM        1198\xe2\x94\x82\nDec 8 07:20:11 PM        1199\xe2\x94\x82     def execute(self, bin, *args, **kwargs):\nDec 8 07:20:11 PM  \nDec 8 07:20:11 PM  ==> Build failed \n
Run Code Online (Sandbox Code Playgroud)\n

我应该怎么做才能解决这个错误?\n谢谢

\n

Nej*_*ono 24

确保您已安装 psycopg2 所需的系统依赖项。在 Ubuntu 或 Debian 上,您可以运行以下命令来安装它们:

sudo apt-get install libpq-dev python3-dev
Run Code Online (Sandbox Code Playgroud)

然后依赖安装成功后再次运行安装。

pip install psycopg2
Run Code Online (Sandbox Code Playgroud)


Mat*_*ias 7

您应该只拥有其中之一

psycopg2 = "^2.9.5"
psycopg2-binary = "^2.9.5"
Run Code Online (Sandbox Code Playgroud)

不是都。

psycopg2 = "^2.9.5"尝试从 pyproject.toml 文件中删除。


Git*_*er0 5

为我解决的是:apt install libpq-dev gcc