2017-06-29 159 views
0

我正在嘗試運行一個建立在CherryPy上的網站,並正在使用Python 2.7.13在新環境中部署它,並一直在努力獲取一切必要的設置。目前我堅持導入pyOpenSSL來啓用SSL支持,但pyOpenSSL無法安裝,因爲沒有安裝必需的模塊Cryptography。所以我一直在努力安裝Cryptography,因爲安裝了所有其他必需的模塊。Python加密模塊導入錯誤

早些時候,我曾使用pip2.7 install cryptography > /tmp/piplog.txt後嘗試安裝模塊和整個輸出記錄到一個單獨的文件,我能夠看到這樣的

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/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: error: openssl/opensslv.h: No such file or directory 
build/temp.linux-x86_64-2.7/_openssl.c:448:27: error: openssl/e_os2.h: No such file or directory 
build/temp.linux-x86_64-2.7/_openssl.c:468:25: error: openssl/aes.h: No such file or directory 
build/temp.linux-x86_64-2.7/_openssl.c:471:26: error: openssl/asn1.h: No such file or directory 

錯誤,這使我看到這些文件目前實際上被安裝了find/-name opensslv.h,然後我從我安裝的OpenSSL複製的文件與

cp -rf /usr/local/ssl/inclue/openssl/* /usr/local/include/python2.7/openssl 

從而使加密模塊會找到相應的文件,好像安裝了一個更遠,但我目前無法理解我在輸出中看到的錯誤。完整的輸出低於

Collecting cryptography 
    Using cached cryptography-1.9.tar.gz 
Requirement already satisfied: idna>=2.1 in /usr/local/lib/python2.7/site-packages (from cryptography) 
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python2.7/site-packages (from cryptography) 
Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from cryptography) 
Requirement already satisfied: enum34 in /usr/local/lib/python2.7/site-packages (from cryptography) 
Requirement already satisfied: ipaddress in /usr/local/lib/python2.7/site-packages (from cryptography) 
Requirement already satisfied: cffi>=1.7 in /usr/local/lib/python2.7/site-packages (from cryptography) 
Requirement already satisfied: pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=1.7->cryptography) 
Installing collected packages: cryptography 
    Running setup.py install for cryptography: started 
    Running setup.py install for cryptography: finished with status 'error' 
    Complete output from command /usr/local/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-VvLC6F/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-iAcBaS-record/install-record.txt --single-version-externally-managed --compile: 
    running install 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-2.7 
    creating build/lib.linux-x86_64-2.7/cryptography 
    copying src/cryptography/exceptions.py -> build/lib.linux-x86_64-2.7/cryptography 
    copying src/cryptography/__init__.py -> build/lib.linux-x86_64-2.7/cryptography 
    copying src/cryptography/utils.py -> build/lib.linux-x86_64-2.7/cryptography 
    copying src/cryptography/__about__.py -> build/lib.linux-x86_64-2.7/cryptography 
    copying src/cryptography/fernet.py -> build/lib.linux-x86_64-2.7/cryptography 
    creating build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/extensions.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/oid.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/base.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/general_name.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/name.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    copying src/cryptography/x509/certificate_transparency.py -> build/lib.linux-x86_64-2.7/cryptography/x509 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat 
    copying src/cryptography/hazmat/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/backends 
    copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends 
    copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings 
    copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/interfaces.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/serialization.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/mac.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/backends/openssl 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/openssl 
    copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/openssl 
    copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/openssl 
    copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/openssl 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/twofactor 
    copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/twofactor 
    copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/twofactor 
    copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/twofactor 
    copying src/cryptography/hazmat/primitives/twofactor/utils.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/twofactor 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/asymmetric 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/ciphers 
    copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/ciphers 
    copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/ciphers 
    copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/ciphers 
    copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/ciphers 
    creating build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-x86_64-2.7/cryptography/hazmat/primitives/kdf 
    running egg_info 
    writing requirements to src/cryptography.egg-info/requires.txt 
    writing src/cryptography.egg-info/PKG-INFO 
    writing top-level names to src/cryptography.egg-info/top_level.txt 
    writing dependency_links to src/cryptography.egg-info/dependency_links.txt 
    writing entry points to src/cryptography.egg-info/entry_points.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-2.7/_padding.c' 
    creating build/temp.linux-x86_64-2.7 
    generating cffi module 'build/temp.linux-x86_64-2.7/_constant_time.c' 
    generating cffi module 'build/temp.linux-x86_64-2.7/_openssl.c' 
    building '_openssl' extension 
    creating build/temp.linux-x86_64-2.7/build 
    creating build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7 
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o 
    build/temp.linux-x86_64-2.7/_openssl.c: In function ‘_setup_ssl_threads’: 
    build/temp.linux-x86_64-2.7/_openssl.c:3400: warning: comparison is always false due to limited range of data type 
    gcc -pthread -shared build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o -lssl -lcrypto -o build/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/_openssl.so 
    /usr/bin/ld: cannot find -lssl 
    collect2: ld returned 1 exit status 
    error: command 'gcc' failed with exit status 1 

    ---------------------------------------- 

回答

0

嗯,看來我也陷入了類似的錯誤像以前一樣,因爲一旦我添加符號鏈接libssl.so和libcrypto.so文件到我的/ usr/lib /目錄。作爲root我做

ln -s /usr/local/ssl/lib/libssl.so /usr/lib/libssl.so 
ln -s /usr/local/ssl/lib/libcrypto.so /usr/lib/libcrypto.so 

之後,我是能夠做成功pip2.7 install cryptographypip2.7 install pyOpenSSL

現在,當我開始了我的CherryPy的網站,我不再獲得有關被要求pyOpenSSL錯誤。

我以前的軟件安裝可能會出現一些菜鳥錯誤,導致文件不在新安裝程序所在的位置,或者我應該知道在那裏放置符號鏈接以避免這些類型的問題。但好的學習經驗