我的操作系统:Mac OS X El Capitan
当我像这样安装加密技术时:
pip install cryptography==0.2.1
错误是:
Collecting cryptography==0.2.1
Using cached cryptography-0.2.1.tar.gz
Complete output from command python setup.py egg_info:
no previously-included directories found matching 'documentation/_build'
zip_safe flag not set; analyzing archive contents...
six: module references __path__
Installed /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/six-1.10.0-py2.7.egg
Searching for cffi>=0.8
Reading https://pypi.python.org/simple/cffi/
Best match: cffi 1.5.0
Downloading https://pypi.python.org/packages/source/c/cffi/cffi-1.5.0.tar.gz#md5=dec8441e67880494ee881305059af656
Processing cffi-1.5.0.tar.gz
Writing /var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/easy_install-ZAtQYR/cffi-1.5.0/setup.cfg
Running cffi-1.5.0/setup.py -q bdist_egg --dist-dir /var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/easy_install-ZAtQYR/cffi-1.5.0/egg-dist-tmp-Dl08xt
creating /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg
Extracting cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg to /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs
Installed /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg
Searching for pycparser
Reading https://pypi.python.org/simple/pycparser/
Best match: pycparser 2.14
Downloading https://pypi.python.org/packages/source/p/pycparser/pycparser-2.14.tar.gz#md5=a2bc8d28c923b4fe2b2c3b4b51a4f935
Processing pycparser-2.14.tar.gz
Writing /var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/easy_install-80l9Lo/pycparser-2.14/setup.cfg
Running pycparser-2.14/setup.py -q bdist_egg --dist-dir /var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/easy_install-80l9Lo/pycparser-2.14/egg-dist-tmp-5dC3Ib
warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
warning: no previously-included files matching 'lextab.*' found under directory 'tests'
warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
warning: no previously-included files matching 'lextab.*' found under directory 'examples'
zip_safe flag not set; analyzing archive contents...
Copying pycparser-2.14-py2.7.egg to /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs
Installed /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/pycparser-2.14-py2.7.egg
running egg_info
creating pip-egg-info/cryptography.egg-info
writing requirements to pip-egg-info/cryptography.egg-info/requires.txt
writing pip-egg-info/cryptography.egg-info/PKG-INFO
writing top-level names to pip-egg-info/cryptography.egg-info/top_level.txt
writing dependency_links to pip-egg-info/cryptography.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/cryptography.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
cryptography/hazmat/bindings/__pycache__/_cffi__xfdb41ad9xb4fc9075.c:369:5: error: conflicting types for 'ASN1_GENERALIZEDTIME_check'
int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *);
^
/usr/local/include/openssl/asn1.h:856:5: note: previous declaration is here
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
^
1 error generated.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/setup.py", line 113, in <module>
"build": cffi_build,
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 180, in run
self.find_sources()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 207, in find_sources
mm.run()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 291, in run
self.add_defaults()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 320, in add_defaults
sdist.add_defaults(self)
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/sdist.py", line 118, in add_defaults
build_py = self.get_finalized_command('build_py')
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
cmd_obj.ensure_finalized()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/site-packages/setuptools/command/build_py.py", line 28, in finalize_options
orig.build_py.finalize_options(self)
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/command/build_py.py", line 46, in finalize_options
('force', 'force'))
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/cmd.py", line 298, in set_undefined_options
src_cmd_obj.ensure_finalized()
File "/Users/username/.pyenv/versions/2.7.11/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/setup.py", line 55, in finalize_options
OpenSSLBinding().ffi.verifier.get_extension(),
File "cryptography/hazmat/bindings/openssl/binding.py", line 83, in __init__
self._ensure_ffi_initialized()
File "cryptography/hazmat/bindings/openssl/binding.py", line 99, in _ensure_ffi_initialized
libraries)
File "cryptography/hazmat/bindings/utils.py", line 72, in build_ffi
ext_package="cryptography",
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg/cffi/api.py", line 433, in verify
lib = self.verifier.load_library()
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg/cffi/verifier.py", line 110, in load_library
self._compile_module()
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg/cffi/verifier.py", line 207, in _compile_module
outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg/cffi/ffiplatform.py", line 29, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose)
File "/private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography/.eggs/cffi-1.5.0-py2.7-macosx-10.11-x86_64.egg/cffi/ffiplatform.py", line 62, in _build
raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.ffiplatform.VerificationError: CompileError: command 'clang' failed with exit status 1
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/48/lrr_y58s4rq70qdnjcvqc8l8j2g31b/T/pip-build-zGO9s0/cryptography
我确定我已将
openssl
升级到最新版本:
$ openssl version
OpenSSL 1.0.2f 28 Jan 2016
但我不知道如何解决它。我什至查了官方文档:
https://cryptography.io/en/latest/installation/#building-cryptography-on-os-x
然后照着做,结果是一样的。
brew
来救援:
brew install openssl
然后
brew
给出提示:
Apple 已弃用 OpenSSL,转而使用自己的 TLS 和加密库
一般来说,这不会对您造成任何后果。如果你建立你的 自己的软件,它需要这个公式,你需要添加到你的 构建变量:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
因此,只需导出这些环境变量并重新运行您最喜欢的 pip install (或者更好地避免将来发生严重破坏,将以下内容添加到您的
~/.bash_profile
:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
这对我来说就像一个魅力!
我已经尝试了几乎所有的方法,但仍然不断收到以下错误:
... SWIG/_m2crypto_wrap.c:5258:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return BIO_do_handshake(bio);
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/openssl/include/openssl/bio.h:502:34: note: expanded from macro 'BIO_do_handshake'
# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:7640:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return BIO_ctrl(bio, BIO_C_SET_SSL, flag, (char *)ssl);
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:7699:19: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
err = ERR_get_error();
~ ^~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:7751:59: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
ms = ((start->tv_sec + (int)timeout) - tv.tv_sec) * 1000;
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
SWIG/_m2crypto_wrap.c:7996:19: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
err = ERR_get_error();
~ ^~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:8026:37: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
r = SSL_write(ssl, buf.buf, buf.len);
~~~~~~~~~ ~~~~^~~
SWIG/_m2crypto_wrap.c:8069:37: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
r = SSL_write(ssl, buf.buf, buf.len);
~~~~~~~~~ ~~~~^~~
SWIG/_m2crypto_wrap.c:8087:19: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
err = ERR_get_error();
~ ^~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:8143:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return SSL_CTX_set_session_cache_mode(ctx, mode);
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/openssl/include/openssl/ssl.h:2484:9: note: expanded from macro 'SSL_CTX_set_session_cache_mode'
SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:8148:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return SSL_CTX_get_session_cache_mode(ctx);
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/openssl/include/openssl/ssl.h:2486:9: note: expanded from macro 'SSL_CTX_get_session_cache_mode'
SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:8680:14: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
outlen = BIO_ctrl_pending(bio);
~ ^~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:8742:14: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
outlen = BIO_ctrl_pending(bio);
~ ^~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:22694:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
arg4 = len;
~ ^~~
SWIG/_m2crypto_wrap.c:25282:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
arg3 = len;
~ ^~~
21 warnings generated.
SWIG/_m2crypto_wrap.c:2894:9: warning: variable 'res' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (PyType_Ready(tp) < 0)
^~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:2918:10: note: uninitialized use occurs here
return res;
^~~
SWIG/_m2crypto_wrap.c:2894:5: note: remove the 'if' if its condition is always false
if (PyType_Ready(tp) < 0)
^~~~~~~~~~~~~~~~~~~~~~~~~
SWIG/_m2crypto_wrap.c:2875:10: note: initialize the variable 'res' to silence this warning
int res;
^
= 0
1 warning generated.
cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include build/temp.macosx-10.13-intel-2.7/SWIG/_m2crypto_wrap.o -L/usr/lib -lssl -lcrypto -o build/lib.macosx-10.13-intel-2.7/M2Crypto/_m2crypto.so
ld: warning: ignoring file /usr/local/opt/openssl/lib/libssl.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/opt/openssl/lib/libssl.dylib
ld: warning: ignoring file /usr/local/opt/openssl/lib/libcrypto.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/opt/openssl/lib/libcrypto.dylib
running install_lib
creating /Library/Python/2.7/site-packages/M2Crypto
error: could not create '/Library/Python/2.7/site-packages/M2Crypto': Permission denied
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q5/qk1gf6z15kschmf5dwb3mqvh0000gn/T/pip-build-WyOs_y/M2crypto/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/q5/qk1gf6z15kschmf5dwb3mqvh0000gn/T/pip-tp6pQY-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/q5/qk1gf6z15kschmf5dwb3mqvh0000gn/T/pip-build-WyOs_y/M2crypto/
我最难让它发挥作用。修复最终是一个简单的
chmod
和 sudo
:
sudo chmod 777 /Library/Python/2.7/site-packages/