【问题标题】:error to install pip install psycopg2 on fedora 23在 Fedora 23 上安装 pip install psycopg2 时出错
【发布时间】:2016-04-07 13:55:15
【问题描述】:

我会做这些事情已经有一段时间了

 ➜  ~  cd ~/project

    ➜  project  source vProject/bin/activate

    (vProject)➜  project  cd edu

    (vProject)➜  edu  pip install pillow

    Requirement already satisfied (use --upgrade to upgrade): pillow in /home/hadi/project/vProject/lib/python2.7/site-packages

以及我安装 psycopg2 的那一刻

(vProject)➜ edu pip install psycopg2

我收到了这个错误

Collecting psycopg2
      Using cached psycopg2-2.6.1.tar.gz
    Building wheels for collected packages: psycopg2
      Running setup.py bdist_wheel for psycopg2
      Complete output from command /home/hadi/project/vProject/bin/python -c "import setuptools;__file__='/tmp/pip-build-K4RBgE/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp_YVqgFpip-wheel-:
      running bdist_wheel
      ...

      In file included from psycopg/psycopgmodule.c:27:0:
      ./psycopg/psycopg.h:31:22: fatal error: libpq-fe.h: No such file or directory
      compilation terminated.
      error: command 'gcc' failed with exit status 1

      ----------------------------------------
      Failed building wheel for psycopg2
    Failed to build psycopg2
    Installing collected packages: psycopg2
      Running setup.py install for psycopg2
        Complete output from command /home/hadi/project/vProject/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-K4RBgE/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-mKANSq-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/hadi/project/vProject/include/site/python2.7/psycopg2:
        running install
        running build
        running build_py
        running build_ext
        building 'psycopg2._psycopg' extension
        gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.6.1 (dt dec pq3 ext lo64)" -DPG_VERSION_HEX=0x090405 -DHAVE_LO64=1 -I/usr/include/python2.7 -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement

        In file included from psycopg/psycopgmodule.c:27:0:

        ./psycopg/psycopg.h:31:22: fatal error: libpq-fe.h: No such file or directory
        compilation terminated.

        error: command 'gcc' failed with exit status 1

        ----------------------------------------
    Command "/home/hadi/project/vProject/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-K4RBgE/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-mKANSq-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/hadi/project/vProject/include/site/python2.7/psycopg2" failed with error code 1 in /tmp/pip-build-K4RBgE/psycopg2

我之前安装过gcc

【问题讨论】:

    标签: python c++ linux python-2.7 fedora


    【解决方案1】:

    您缺少安装它所需的库。我相信你需要安装的包是postgresql-devel

    【讨论】:

      【解决方案2】:

      根据您在 virtualenv 中运行的 Python 版本,运行以下命令之一:

      Python 2.x:

      sudo dnf install python-devel

      Python 3.x:

      sudo dnf install python3-devel

      【讨论】:

        【解决方案3】:

        第 1 步: 对于 rpm linux

        sudo dnf install python-devel postgresql-devel rpm-build

        deb linux

        sudo apt-get install libpq-dev python-dev build-essential

        第 2 步: 在你里面virtualenv

        pip install psycopg2

        【讨论】:

        • 同样的问题,但来自gcc 命令的错误是另一个丢失的文件:./psycopg/psycopg.h:31:22: fatal error: libpq-fe.h: No such file or directory。我已经看到对apt-get install libpq-dev 的建议,但无济于事。此外,在venv 之外安装psycopg2 也可以正常工作。有关如何解决此丢失文件的任何建议?
        【解决方案4】:

        试试这个,它适用于我我正在使用 fedora 33

        pip install psycopg2-binary
        

        【讨论】:

          【解决方案5】:

          运行这个命令对我有用

          sudo dnf install python3-devel
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-07-17
            • 2018-09-23
            • 2013-06-25
            • 1970-01-01
            • 2020-12-11
            • 2017-02-07
            • 2012-12-22
            相关资源
            最近更新 更多