greyli / bluelog

Check out the newer version (2024) of this project: https://github.com/greyli/greybook
MIT License
454 stars 662 forks source link

pip安装python依赖psycopg2报错 #37

Closed BarryCui closed 3 years ago

BarryCui commented 3 years ago

当使用pipenv install --dev或pip install -r requirements.txt安装python依赖时,报错如下:

    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/psycopg
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext) -DPG_VERSION_NUM=90224 -I/home/vagrant/bluelog/env/include -I/usr/include/python3.6m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.6/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    In file included from psycopg/psycopgmodule.c:27:0:
    ./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.

    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

把requirements.txt里的psycopg2==2.8.4改成psycopg2-binary就能正常安装了。

Histra commented 3 years ago

使用pipenv的话,把Pipfile中的"psycopg2" = "*"换成"psycopg2-binary" = "*"即可。

greyli commented 3 years ago

把这个依赖去掉了,它只在本地测试 Heroku 部署的时候才会用到(书中对应位置已有相应安装命令)。感谢反馈!