【问题标题】:gcc cant find Python.hgcc 找不到 Python.h
【发布时间】:2020-08-30 18:09:28
【问题描述】:

正如标题所说,我试图在 Fedora 发行版中安装 netifaces 库,使用 pip3 install netifaces 并且我不断收到以下错误。

        1 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1

我使用locate Python.h 搜索Python.h,并在/usr/include/python2.7/Python.h 找到它。

下一步,我尝试安装dnf install python-dev(没有找到包)然后尝试dnf install python3.8-dev

但这根本不能解决我的问题,我仍然无法安装netifaces库,因为gcc找不到Python.h(我有一个旧版本的2.7) p>

这是我运行 pip3 install netifaces 时的完整输出:

Defaulting to user installation because normal site-packages is not writeable
Collecting netifaces
  Downloading netifaces-0.10.9.tar.gz (28 kB)
Using legacy 'setup.py install' for netifaces, since package 'wheel' is not installed.
Installing collected packages: netifaces
    Running setup.py install for netifaces ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-743bfly4/netifaces/setup.py'"'"'; __file__='"'"'/tmp/pip-install-743bfly4/netifaces/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-panq4br6/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ablil/.local/include/python3.8/netifaces                                             
         cwd: /tmp/pip-install-743bfly4/netifaces/                                                  
    Complete output (20 lines):                                                                     
    running install                                                                                 
    running build                                                                                   
    running build_ext                                                                               
    checking for getifaddrs...found.                                                                
    checking for getnameinfo...found.                                                               
    checking for IPv6 socket IOCTLs...not found.                                                    
    checking for optional header files...netash/ash.h netatalk/at.h netax25/ax25.h neteconet/ec.h netipx/ipx.h netpacket/packet.h netrose/rose.h linux/atm.h linux/llc.h linux/tipc.h linux/dn.h.       
    checking whether struct sockaddr has a length field...no.                                       
    checking which sockaddr_xxx structs are defined...at ax25 in in6 ipx un rose ash ec ll atmpvc atmsvc dn llc.                                                                                        
    checking for routing socket support...no.                                                       
    checking for sysctl(CTL_NET...) support...no.                                                   
    checking for netlink support...yes.                                                             
    will use netlink to read routing table                                                          
    building 'netifaces' extension                                                                  
    gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DNETIFACES_VERSION=0.10.9 -DHAVE_GETIFADDRS=1 -DHAVE_GETNAMEINFO=1 -DHAVE_NETASH_ASH_H=1 -DHAVE_NETATALK_AT_H=1 -DHAVE_NETAX25_AX25_H=1 -DHAVE_NETECONET_EC_H=1 -DHAVE_NETIPX_IPX_H=1 -DHAVE_NETPACKET_PACKET_H=1 -DHAVE_NETROSE_ROSE_H=1 -DHAVE_LINUX_ATM_H=1 -DHAVE_LINUX_LLC_H=1 -DHAVE_LINUX_TIPC_H=1 -DHAVE_LINUX_DN_H=1 -DHAVE_SOCKADDR_AT=1 -DHAVE_SOCKADDR_AX25=1 -DHAVE_SOCKADDR_IN=1 -DHAVE_SOCKADDR_IN6=1 -DHAVE_SOCKADDR_IPX=1 -DHAVE_SOCKADDR_UN=1 -DHAVE_SOCKADDR_ROSE=1 -DHAVE_SOCKADDR_ASH=1 -DHAVE_SOCKADDR_EC=1 -DHAVE_SOCKADDR_LL=1 -DHAVE_SOCKADDR_ATMPVC=1 -DHAVE_SOCKADDR_ATMSVC=1 -DHAVE_SOCKADDR_DN=1 -DHAVE_SOCKADDR_LLC=1 -DHAVE_PF_NETLINK=1 -I/usr/include/python3.8 -c netifaces.c -o build/temp.linux-x86_64-3.8/netifaces.o
    netifaces.c:1:10: fatal error: Python.h: No such file or directory
        1 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-743bfly4/netifaces/setup.py'"'"'; __file__='"'"'/tmp/pip-install-743bfly4/netifaces/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-panq4br6/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/ablil/.local/include/python3.8/netifaces Check the logs for full command output.

【问题讨论】:

  • 试试sudo dnf install python3-devel,应该可以解决问题

标签: python python-3.x linux gcc


【解决方案1】:

解决方案

sudo dnf install python3-devel

ps:所有功劳归Venky。为了更清楚,我只是添加了答案。 OP,请添加这个被接受的答案。

【讨论】:

    猜你喜欢
    • 2014-03-17
    • 2016-09-17
    • 2021-11-29
    • 2015-05-13
    • 1970-01-01
    • 2012-01-07
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多