簡體   English   中英

如何使用 psycopg2 修復我的 docker compose 錯誤

[英]how fix my docker compose error with psycopg2

我正在配置 Docker 以使用 Django,但我在運行 Docker 時遇到問題,這可能是 Psycopg 問題,我應該如何解決這個問題?

我的碼頭工人錯誤:

Uninstalling psycopg2-2.8.4:
      Successfully uninstalled psycopg2-2.8.4
    Running setup.py install for psycopg2: started
    Running setup.py install for psycopg2: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-71k484j0/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-71k484j0/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-klbk9cly/install-record.txt --single-version-externally-managed --compile
         cwd: /tmp/pip-install-71k484j0/psycopg2/
    Complete output (72 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    creating build/lib.linux-x86_64-3.8/psycopg2
    copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/psycopg1.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
    copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
    creating build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_bug_gc.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_lobject.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_sql.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/dbapi20_tpc.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_quote.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_psycopg2_dbapi20.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/testconfig.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_dates.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_notify.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_errcodes.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_connection.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_cancel.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_replication.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_bugX000.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_fast_executemany.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_copy.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_green.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_types_basic.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_cursor.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_async_keyword.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_types_extras.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_with.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/testutils.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_extras_dictcursor.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_module.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/dbapi20.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_transaction.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    copying tests/test_async.py -> build/lib.linux-x86_64-3.8/psycopg2/tests
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/psycopg
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION=2.7.7 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=110005 -DHAVE_LO64=1 -I/usr/local/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/11/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    psycopg/psycopgmodule.c: In function ‘psyco_is_main_interp’:
    psycopg/psycopgmodule.c:689:18: error: dereferencing pointer to incomplete type ‘PyInterpreterState’ {aka ‘struct _is’}
         while (interp->next)
                      ^~

    It appears you are missing some prerequisite to build the package from source.

    You may install a binary package by installing 'psycopg2-binary' from PyPI.
    If you want to install psycopg2 from source, please install the packages
    required for the build and try again.

    For further information please check the 'doc/src/install.rst' file (also at
    <http://initd.org/psycopg/docs/install.html>).

    error: command 'gcc' failed with exit status 1
    ----------------------------------------

文件:

FROM python:3
RUN export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
RUN pip3 install psycopg2-binary
RUN pip3 install psycopg2
ENV PYTHONUNBUFFERED 0
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

我嘗試安裝 Psycopg2-Binary,但它仍然存在

3 天以來,我一直遇到與 Docker 相關的安裝問題。

有人有什么好主意嗎?

更新到 psycopg2.8 或更高版本以支持最新的 python https://github.com/psycopg/psycopg2/issues/854

請在你的 docker 文件中運行,你需要安裝一些額外的依賴,python 開發,psql contrib 等

sudo apt update
sudo apt-get install  postgresql-contrib
sudo apt-get install libpq-dev gcc # this is required as psycopg2 uses pg_config
sudo apt-get install python3-dev

當然,apt 安裝應該在 pip 安裝之前進行。

進一步在您運行pip install ....腳本中,請將其更改為pip3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM