解決centos中的 openssl/opensslv.h找不到的相關問題
引言: scrapy是Python中鼎鼎大名的爬蟲架構,在安裝scrapy過程中碰到了openssl某個檔案找不到的問題,並進行了分析,記錄之。
1. scrapy以及安裝過程
Scrapy是Python中鼎鼎大名的爬蟲架構,筆者在Centos 7系統之上進行安裝,發現了如下問題:
>> pip install scrapy
由於安裝過程中的過程資訊比較多,這裡只列出了其中的關鍵片段資訊:
[html]view plaincopy
- runningegg_info
- writingrequirementstosrc/cryptography.egg-info/requires.txt
- writingsrc/cryptography.egg-info/PKG-INFO
- writingtop-levelnamestosrc/cryptography.egg-info/top_level.txt
- writingdependency_linkstosrc/cryptography.egg-info/dependency_links.txt
- writingentrypointstosrc/cryptography.egg-info/entry_points.txt
- readingmanifestfile'src/cryptography.egg-info/SOURCES.txt'
- readingmanifesttemplate'MANIFEST.in'
- nopreviously-includeddirectoriesfoundmatching'docs/_build'
- warning:nopreviously-includedfilesmatching'*'foundunderdirectory'vectors'
- writingmanifestfile'src/cryptography.egg-info/SOURCES.txt'
- runningbuild_ext
- generatingcffimodule'build/temp.linux-x86_64-2.7/_padding.c'
- creatingbuild/temp.linux-x86_64-2.7
- generatingcffimodule'build/temp.linux-x86_64-2.7/_constant_time.c'
- generatingcffimodule'build/temp.linux-x86_64-2.7/_openssl.c'
- building'_openssl'extension
- creatingbuild/temp.linux-x86_64-2.7/build
- creatingbuild/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7
- gcc-pthread-fno-strict-aliasing-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-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-I/usr/include/python2.7-cbuild/temp.linux-x86_64-2.7/_openssl.c-obuild/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o
- build/temp.linux-x86_64-2.7/_openssl.c:434:30:fatalerror:openssl/opensslv.h:Nosuchfileordirectory
- #include<openssl/opensslv.h>
- ^
- compilationterminated.
- error:command'gcc'failedwithexitstatus1
- ----------------------------------------
- Command"/usr/bin/python2-u-c"importsetuptools,tokenize;__file__='/tmp/pip-build-hRMlG0/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-ReCoWo-record/install-record.txt--single-version-externally-managed--compile"failedwitherrorcode1in/tmp/pip-build-hRMlG0/cryptography/
- [root@AY131203102210033c39Z~]#yuminstallopensslbuild/temp.linux-x86_64-2.7/_openssl.c:434:30:fatalerror:openssl/opensslv.h:Nosuchfileordirectory
- ^C
- Exitingonusercancel.
由於確實openssl.c檔案而安裝失敗了,貌似沒有找到對應的檔案
2. 問題分析
首先懷疑openssl沒有安裝,故先進行openssl的檢查:
>> yum info openssl
[html]view plaincopy
- Loadedplugins:fastestmirror
- Loadingmirrorspeedsfromcachedhostfile
- *base:mirrors.aliyun.com
- *epel:mirrors.aliyun.com
- *extras:mirrors.aliyun.com
- *updates:mirrors.aliyun.com
- InstalledPackages
- Name:openssl
- Arch:x86_64
- Epoch:1
- Version:1.0.1e
- Release:60.el7_3.1
- Size:1.5M
- Repo:installed
- Summary:UtilitiesfromthegeneralpurposecryptographylibrarywithTLSimplementation
- URL:http://www.openssl.org/
- License:OpenSSL
- Description:TheOpenSSLtoolkitprovidessupportforsecurecommunicationsbetween
- :machines.OpenSSLincludesacertificatemanagementtoolandshared
- :librarieswhichprovidevariouscryptographicalgorithmsand
- :protocols.
基於其中的資訊可以得知,openssl是一家安裝過了,怎麼還是會缺少openssl.c的檔案呢?
經過一番思考,豁然發現一個基本規則, openssl已經安裝二進位的可執行程式,而這裡的安裝scrapy則需要的是openssl的源檔案程式,比如openssl.h。故這裡需要匯集安裝的是openssh.h的開發版,其中包含相關的安裝原始碼檔案。
3. 問題的解決
在確認了問題之後,接下來就是安裝openssl-devel的安裝包了:
>> yum install openssl-devel
在安裝完成之後,重新安裝scrapy,就可以順利安裝成功了
4. 總結
推而廣之,在Linux系統中都存在類似的問題,在安裝特定安裝包的過程中,其依賴某些第三方開發包,會曝出某些檔案找不到的錯誤,一般情況下是需要安裝依賴包的開發版本的。 這個規則應該是通用的。