2017-06-29 133 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错误。

我以前的软件安装可能会出现一些菜鸟错误,导致文件不在新安装程序所在的位置,或者我应该知道在那里放置符号链接以避免这些类型的问题。但好的学习经验