unbantu18.04 安装包时报错 bitarray/_bitarray.c:12:10: fatal error: Python.h: No such file or directory
#include "Python.h"
sudo pip3 install pybloom_live
WARNING: The directory '/home/tank/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pybloom_live
Downloading pybloom_live-3.0.0.tar.gz (6.9 kB)
Collecting bitarray>=0.3.4
Downloading bitarray-1.9.1.tar.gz (70 kB)
|████████████████████████████████| 70 kB 654 kB/s
Building wheels for collected packages: pybloom-live, bitarray
Building wheel for pybloom-live (setup.py) ... done
Created wheel for pybloom-live: filename=pybloom_live-3.0.0-py3-none-any.whl size=8346 sha256=167b8fb36984cb9d180068bd49473a7dfc17f041d7c163d5b1dd60c9caa70d3b
Stored in directory: /tmp/pip-ephem-wheel-cache-ql6kwd4t/wheels/43/a1/0b/22d091e06a2fef8bcfdb739fc938a199a2c086227fef2375da
Building wheel for bitarray (setup.py) ... 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-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/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-46ephkdq
cwd: /tmp/pip-install-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/
Complete output (23 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/bitarray
copying bitarray/test_bitarray.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/__init__.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/util.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/test_util.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/pythoncapi_compat.h -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/bitarray.h -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/test_data.pickle -> build/lib.linux-x86_64-3.6/bitarray
running build_ext
building 'bitarray._bitarray' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/bitarray
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -c bitarray/_bitarray.c -o build/temp.linux-x86_64-3.6/bitarray/_bitarray.o
bitarray/_bitarray.c:12:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for bitarray
Running setup.py clean for bitarray
Successfully built pybloom-live
Failed to build bitarray
Installing collected packages: bitarray, pybloom-live
Running setup.py install for bitarray ... 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-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/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-oqdnp21v/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6/bitarray
cwd: /tmp/pip-install-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/
Complete output (23 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/bitarray
copying bitarray/test_bitarray.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/__init__.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/util.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/test_util.py -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/pythoncapi_compat.h -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/bitarray.h -> build/lib.linux-x86_64-3.6/bitarray
copying bitarray/test_data.pickle -> build/lib.linux-x86_64-3.6/bitarray
running build_ext
building 'bitarray._bitarray' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/bitarray
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -c bitarray/_bitarray.c -o build/temp.linux-x86_64-3.6/bitarray/_bitarray.o
bitarray/_bitarray.c:12:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-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-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/setup.py'"'"'; __file__='"'"'/tmp/pip-install-to62rgck/bitarray_5df67fd959894e8f9e56854e41097cdb/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-oqdnp21v/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6/bitarray Check the logs for full command output.
这种错误是因为没有安装对应的python dev工具造成的,解决方法也很简单,安装对应的dev工具即可
# python2 系列
sudo apt-get install python-dev
python3.6 系列。可以使用python --version命令查看自己对应的版本,然后更改版本号就好了
sudo apt-get install python3.6-dev
安装完成后再次执行对应安装包的命令
pip3 install pybloom_live
Defaulting to user installation because normal site-packages is not writeable
Collecting pybloom_live
Using cached pybloom_live-3.0.0-py3-none-any.whl
Collecting bitarray>=0.3.4
Using cached bitarray-1.9.1.tar.gz (70 kB)
Building wheels for collected packages: bitarray
Building wheel for bitarray (setup.py) ... done
Created wheel for bitarray: filename=bitarray-1.9.1-cp36-cp36m-linux_x86_64.whl size=141992 sha256=f06b504cd24e583eb6a173c6ef7bdda79b0e36b9822f285c1edc5752ba793c1a
Stored in directory: /home/tank/.cache/pip/wheels/1b/a6/c1/4d3172d54f65afcc08c3c0eb413fde7ae6cc90ba91ebfe5628
Successfully built bitarray
Installing collected packages: bitarray, pybloom-live
Successfully installed bitarray-1.9.1 pybloom-live-3.0.0
完美解决,赶紧去试一试吧!