pip install PyGreSQL 失败并出现致命错误

pip install PyGreSQL 失败并出现致命错误

执行的命令:pip3 install PyGreSQL

失败并出现以下错误。

致命错误:linux/limits.h:没有这样的文件或目录

错误:命令‘cc’失败,退出状态为 1

/tmp/pip-install-x3puix39/PyGreSql/ 中出现错误代码 1 失败

完整日志:

pip install PyGreSQL
The directory '/home/ec2-user/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ec2-user/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting PyGreSQL
  Downloading https://files.pythonhosted.org/packages/4a/65/03b1cd9b6daaa4e32ee72dd5fb1a01fbb7cd0dfe5439e34af6caa6ec60dc/PyGreSQL-5.0.6.tar.gz (648kB)
    100% |████████████████████████████████| 655kB 27.8MB/s 
Installing collected packages: PyGreSQL
  Running setup.py install for PyGreSQL ... error
    Complete output from command /home/linuxbrew/.linuxbrew/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-i1r203v3/PyGreSQL/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-_3noeeqb/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    copying pg.py -> build/lib.linux-x86_64-3.7
    copying pgdb.py -> build/lib.linux-x86_64-3.7
    running build_ext
    building '_pg' extension
    creating build/temp.linux-x86_64-3.7
    cc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPYGRESQL_VERSION=5.0.6 -DDIRECT_ACCESS -DLARGE_OBJECTS -DDEFAULT_VARS -DESCAPING_FUNCS -I/home/linuxbrew/.linuxbrew/opt/python/include/python3.7m -I/home/linuxbrew/.linuxbrew/Cellar/postgresql/11.1_1/include -I/home/linuxbrew/.linuxbrew/include -I/home/linuxbrew/.linuxbrew/opt/openssl/include -I/home/linuxbrew/.linuxbrew/opt/sqlite/include -I/home/linuxbrew/.linuxbrew/opt/python/include/python3.7m -c pgmodule.c -o build/temp.linux-x86_64-3.7/pgmodule.o -O2 -funsigned-char -Wall -Werror
    In file included from /home/linuxbrew/.linuxbrew/include/bits/posix1_lim.h:160:0,
                     from /home/linuxbrew/.linuxbrew/include/limits.h:143,
                     from /home/linuxbrew/.linuxbrew/Cellar/gcc/5.5.0_4/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include-fixed/limits.h:168,
                     from /home/linuxbrew/.linuxbrew/Cellar/gcc/5.5.0_4/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include-fixed/syslimits.h:7,
                     from /home/linuxbrew/.linuxbrew/Cellar/gcc/5.5.0_4/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include-fixed/limits.h:34,
                     from /home/linuxbrew/.linuxbrew/opt/python/include/python3.7m/Python.h:11,
                     from pgmodule.c:32:
    /home/linuxbrew/.linuxbrew/include/bits/local_lim.h:38:26: fatal error: linux/limits.h: No such file or directory
    compilation terminated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
Command "/home/linuxbrew/.linuxbrew/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-i1r203v3/PyGreSQL/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-_3noeeqb/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-i1r203v3/PyGreSQL/

我的Linux发行版:

cat /etc/*release
NAME="Amazon Linux AMI"
VERSION="2018.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2018.03"
PRETTY_NAME="Amazon Linux AMI 2018.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
Amazon Linux AMI release 2018.03

更新:sudo yum install kernerl-devel没有用。执行后出现同样的错误

答案1

尝试 libc-dev 包;但也要查看并确保您想要的标头存在/usr/include/linux/,并且您$PATH或可能设置C_INCLUDE_PATH变量以确保编译器知道在哪里找到库标头。

相关内容