在Linux下安裝Python的Scrapy模塊時出現這個錯誤提示:css
error: command 'gcc' failed with exit status 1
完整的安裝過程及出錯信息以下:python
$ python3 -m pip install scrapy Collecting scrapy Downloading http://pypi.doubanio.com/packages/6e/c2/2b35c88dec01745fe2b068c9187c7dc966b063a0502e26fce19cd18cbd9d/Scrapy-1.3.0-py2.py3-none-any.whl (239kB) 100% |████████████████████████████████| 245kB 693kB/s Requirement already satisfied: six>=1.5.2 in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Requirement already satisfied: parsel>=0.9.5 in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Collecting queuelib (from scrapy) Downloading http://pypi.doubanio.com/packages/16/4f/b307fc978a21bfbb138e8e01a9f4953191d439e30578f5e4fd5befa77de1/queuelib-1.4.2-py2.py3-none-any.whl Collecting service-identity (from scrapy) Downloading http://pypi.doubanio.com/packages/80/f5/8b1604e4d85ce60333a2fd4bc7b7743b21949b434b7c1c2c77eee9e7cd6f/service_identity-16.0.0-py2.py3-none-any.whl Collecting pyOpenSSL (from scrapy) Downloading http://pypi.doubanio.com/packages/ac/93/b4cd538d31adacd07f83013860db6b88d78755af1f3fefe68ec22d397e7b/pyOpenSSL-16.2.0-py2.py3-none-any.whl (43kB) 100% |████████████████████████████████| 51kB 193kB/s Requirement already satisfied: w3lib>=1.15.0 in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Requirement already satisfied: lxml in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Collecting Twisted>=13.1.0 (from scrapy) Downloading http://pypi.doubanio.com/packages/dc/c0/a0114a6d7fa211c0904b0de931e8cafb5210ad824996cc6a9d67f3bae22c/Twisted-16.6.0.tar.bz2 (3.0MB) 100% |████████████████████████████████| 3.0MB 605kB/s Requirement already satisfied: cssselect>=0.9 in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Requirement already satisfied: PyDispatcher>=2.0.5 in ./scrapy_env/lib/python3.5/site-packages (from scrapy) Requirement already satisfied: pyasn1 in ./scrapy_env/lib/python3.5/site-packages (from service-identity->scrapy) Requirement already satisfied: pyasn1-modules in ./scrapy_env/lib/python3.5/site-packages (from service-identity->scrapy) Requirement already satisfied: attrs in ./scrapy_env/lib/python3.5/site-packages (from service-identity->scrapy) Collecting cryptography>=1.3.4 (from pyOpenSSL->scrapy) Downloading http://pypi.doubanio.com/packages/99/df/71c7260003f5c469cec3db4c547115df39e9ce6c719a99e067ba0e78fd8a/cryptography-1.7.2.tar.gz (420kB) 100% |████████████████████████████████| 430kB 651kB/s Requirement already satisfied: zope.interface>=4.0.2 in ./scrapy_env/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy) Requirement already satisfied: constantly>=15.1 in ./scrapy_env/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy) Requirement already satisfied: incremental>=16.10.1 in ./scrapy_env/lib/python3.5/site-packages (from Twisted>=13.1.0->scrapy) Requirement already satisfied: idna>=2.0 in ./scrapy_env/lib/python3.5/site-packages (from cryptography>=1.3.4->pyOpenSSL->scrapy) Requirement already satisfied: setuptools>=11.3 in ./scrapy_env/lib/python3.5/site-packages (from cryptography>=1.3.4->pyOpenSSL->scrapy) Requirement already satisfied: cffi>=1.4.1 in ./scrapy_env/lib/python3.5/site-packages (from cryptography>=1.3.4->pyOpenSSL->scrapy) Requirement already satisfied: pycparser in ./scrapy_env/lib/python3.5/site-packages (from cffi>=1.4.1->cryptography>=1.3.4->pyOpenSSL->scrapy) Installing collected packages: queuelib, cryptography, pyOpenSSL, service-identity, Twisted, scrapy Running setup.py install for cryptography ... error Complete output from command /home/cavin/Code/Python/scrapy_env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-71s5o_mk/cryptography/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-6ppxgrzh-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/cavin/Code/Python/scrapy_env/include/site/python3.5/cryptography: running install running build running build_py creating build creating build/lib.linux-x86_64-3.5 creating build/lib.linux-x86_64-3.5/cryptography copying src/cryptography/utils.py -> build/lib.linux-x86_64-3.5/cryptography copying src/cryptography/fernet.py -> build/lib.linux-x86_64-3.5/cryptography copying src/cryptography/exceptions.py -> build/lib.linux-x86_64-3.5/cryptography copying src/cryptography/__init__.py -> build/lib.linux-x86_64-3.5/cryptography copying src/cryptography/__about__.py -> build/lib.linux-x86_64-3.5/cryptography creating build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/oid.py -> build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/name.py -> build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/general_name.py -> build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/extensions.py -> build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/base.py -> build/lib.linux-x86_64-3.5/cryptography/x509 copying src/cryptography/x509/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/x509 creating build/lib.linux-x86_64-3.5/cryptography/hazmat copying src/cryptography/hazmat/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/serialization.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives creating build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings creating build/lib.linux-x86_64-3.5/cryptography/hazmat/backends copying src/cryptography/hazmat/backends/multibackend.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/twofactor copying src/cryptography/hazmat/primitives/twofactor/utils.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/twofactor copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/twofactor copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/twofactor copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/twofactor creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/kdf creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/interfaces copying src/cryptography/hazmat/primitives/interfaces/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/interfaces creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/ciphers copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/ciphers copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/ciphers copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/ciphers copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/ciphers creating build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/primitives/asymmetric creating build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/openssl copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/openssl copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/openssl copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/openssl creating build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/commoncrypto copying src/cryptography/hazmat/bindings/commoncrypto/binding.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/commoncrypto copying src/cryptography/hazmat/bindings/commoncrypto/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/bindings/commoncrypto creating build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/openssl creating build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto copying src/cryptography/hazmat/backends/commoncrypto/hmac.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto copying src/cryptography/hazmat/backends/commoncrypto/hashes.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto copying src/cryptography/hazmat/backends/commoncrypto/ciphers.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto copying src/cryptography/hazmat/backends/commoncrypto/backend.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto copying src/cryptography/hazmat/backends/commoncrypto/__init__.py -> build/lib.linux-x86_64-3.5/cryptography/hazmat/backends/commoncrypto running egg_info writing entry points to src/cryptography.egg-info/entry_points.txt writing requirements to src/cryptography.egg-info/requires.txt writing top-level names to src/cryptography.egg-info/top_level.txt writing src/cryptography.egg-info/PKG-INFO writing dependency_links to src/cryptography.egg-info/dependency_links.txt warning: manifest_maker: standard file '-c' not found reading manifest file 'src/cryptography.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' no previously-included directories found matching 'docs/_build' warning: no previously-included files matching '*' found under directory 'vectors' writing manifest file 'src/cryptography.egg-info/SOURCES.txt' running build_ext generating cffi module 'build/temp.linux-x86_64-3.5/_padding.c' creating build/temp.linux-x86_64-3.5 generating cffi module 'build/temp.linux-x86_64-3.5/_constant_time.c' generating cffi module 'build/temp.linux-x86_64-3.5/_openssl.c' building '_openssl' extension creating build/temp.linux-x86_64-3.5/build creating build/temp.linux-x86_64-3.5/build/temp.linux-x86_64-3.5 gcc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DDYNAMIC_ANNOTATIONS_ENABLED=1 -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 -I/home/cavin/Code/Python/scrapy_env/include -I/usr/include/python3.5m -c build/temp.linux-x86_64-3.5/_openssl.c -o build/temp.linux-x86_64-3.5/build/temp.linux-x86_64-3.5/_openssl.o build/temp.linux-x86_64-3.5/_openssl.c:12:24: fatal error: pyconfig.h: No such file or directory # include <pyconfig.h> ^ compilation terminated. error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/home/cavin/Code/Python/scrapy_env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-71s5o_mk/cryptography/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-6ppxgrzh-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/cavin/Code/Python/scrapy_env/include/site/python3.5/cryptography" failed with error code 1 in /tmp/pip-build-71s5o_mk/cryptography/
經由搜索獲得的結果,幾乎都是說要安裝python-dev(Ubuntu)或者python-devel(Centos),可是我運行sudo dnf install python-devel
卻獲得提示說這個依賴已經存在了。而後把網上提到的相關的幾個包都安裝了,錯誤仍是同樣。linux
直到後來看到國外一個博客的文章,受到啓發:
http://alexsleat.co.uk/2011/01/01/fatal-error-python-h-no-such-file-or-directory/scrapy
它裏面說到和其它答案不同的地方是,它明確地指出了python版本,命令以下:ide
sudo apt-get install python2.6-dev
因而我想到:個人fedora裏面同時存在python2和python3,並且默認的是python2,而我如今是要在python3下安裝scrapy,因此是否是也要指明是python3.5-devel呢?。因而嘗試了下:ui
sudo dnf install python3.5-devel
出錯了,好像是提示沒有這個包。而後我改了一下:spa
sudo dnf install python3-devel
這下成功了!而後再安裝Scrapy3d
python3 -m pip install scrapy
終於成功了!code