【问题标题】:Error installing psycopg2 on Manjaro OS in order to use postgresql in django在 Manjaro OS 上安装 psycopg2 以在 django 中使用 postgresql 时出错
【发布时间】:2020-05-02 12:03:27
【问题描述】:

我在 manjaro。 我刚刚从mysql迁移到postgresql。 在安装 postgresql 遇到很多困难后,我得到了错误:( 想要安装 psycopg2 时的最终结果:

pip install psycopg2

结果是:

Collecting psycopg2
  Using cached https://files.pythonhosted.org/packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz
Building wheels for collected packages: psycopg2
  Building wheel for psycopg2 (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/nima/project/django/coders/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bc661h33/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bc661h33/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-w4_ngmz0 --python-tag cp36
       cwd: /tmp/pip-install-bc661h33/psycopg2/
  Complete output (36 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/psycopg2
  copying lib/compat.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/errors.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/_json.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/tz.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/extensions.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/__init__.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/_range.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/extras.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/sql.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/errorcodes.py -> build/lib.linux-x86_64-3.6/psycopg2
  copying lib/pool.py -> build/lib.linux-x86_64-3.6/psycopg2
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/psycopg
  x86_64-conda_cos6-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -Wstrict-prototypes -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120001 -DHAVE_LO64=1 -I/home/nima/anaconda3/include/python3.6m -I. -I/usr/include -I/usr/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.6/psycopg/psycopgmodule.o -Wdeclaration-after-statement
  unable to execute 'x86_64-conda_cos6-linux-gnu-gcc': No such file or directory

  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 'x86_64-conda_cos6-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2
  Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
    Running setup.py install for psycopg2 ... error
    ERROR: Command errored out with exit status 1:
     command: /home/nima/project/django/coders/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bc661h33/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bc661h33/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-hkcgaxlg/install-record.txt --single-version-externally-managed --compile --install-headers /home/nima/project/django/coders/env/include/site/python3.6/psycopg2
         cwd: /tmp/pip-install-bc661h33/psycopg2/
    Complete output (36 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/psycopg2
    copying lib/compat.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/errors.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_json.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/tz.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/extensions.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/__init__.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_range.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/extras.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/sql.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/errorcodes.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/pool.py -> build/lib.linux-x86_64-3.6/psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/psycopg
    x86_64-conda_cos6-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -Wstrict-prototypes -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120001 -DHAVE_LO64=1 -I/home/nima/anaconda3/include/python3.6m -I. -I/usr/include -I/usr/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.6/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    unable to execute 'x86_64-conda_cos6-linux-gnu-gcc': No such file or directory

    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 'x86_64-conda_cos6-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/nima/project/django/coders/env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bc661h33/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bc661h33/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-hkcgaxlg/install-record.txt --single-version-externally-managed --compile --install-headers /home/nima/project/django/coders/env/include/site/python3.6/psycopg2 Check the logs for full command output.

我要安装它做什么?!

djang 版本:3 操作系统:manjaro 来自 aur 的 postgresql(最新版​​本)

我可以在没有 psycopg2 的情况下使用 postgres 吗????

【问题讨论】:

  • 你试过用pip install psycopg2-binary安装吗?
  • 您需要在系统上安装 build-essential(gcc 是其中的一部分)。在 Debian/Ubuntu 系统上,您可以使用 sudo apt-get install build-essential 来执行此操作,但我从未听说过 manjaro。
  • 我在 manjaro。它使用 pacman 并且 pacman 没有构建必需的
  • 它成功了。谢谢!

标签: django postgresql psycopg2


【解决方案1】:

答案就在您向我们展示的错误中:

您可以通过从 PyPI 安装“psycopg2-binary”来安装二进制包。 如果您想从源代码安装 psycopg2,请安装软件包 构建所需的,然后重试。

所以要么尝试pip install psycopg2-binary,要么确保在从源代码安装之前安装gcc

请注意,即使您安装了gcc,也可能会出现其他错误,在这种情况下,您还需要安装这些丢失的软件包,直到不再出现错误为止。在常见的 Linux 发行版上,您会发现 build-essential 包,其中包括用于构建其他包的最常用包。在 Manjaro/Arch linux 上,这是 base-devel 包。

【讨论】:

    猜你喜欢
    • 2012-01-14
    • 2023-03-11
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多