如何在Mac OS X上安装加密?

时间:2016-02-02 07:44:24

标签: python macos cryptography pip

我的操作系统: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

按照这样做,结果是一样的。

3 个答案:

答案 0 :(得分:5)

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

所以只需导出这些env vars并重新运行您最喜欢的pip安装(或者更好以避免在将来添加以下~/.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"

这对我来说就像一个魅力!

答案 1 :(得分:4)

尝试安装scrapy我需要在Mac OS El Capitan上安装加密包。正如Cryptography installation doc

中所述

env LDFLAGS =&#34; -L $(brew --prefix openssl)/ lib&#34; CFLAGS =&#34; -I $(brew --prefix openssl)/ include&#34; pip安装加密

答案 2 :(得分:-1)

我曾尝试过关于此的所有内容但仍然遇到以下错误:    ... SWIG / _m2crypto_wrap.c:5258:12:警告:隐式转换失去整数精度:&#39; long&#39;到&#39; int&#39; [-Wshorten-64至32]         返回BIO_do_handshake(bio);         ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~     /usr/local/opt/openssl/include/openssl/bio.h:502:34:注意:从宏扩展&#39; BIO_do_handshake&#39;     #define BIO_do_handshake(b)BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)                                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:7640:12:警告:隐式转换失去整数精度:&#39; long&#39;到&#39; int&#39; [-Wshorten-64至32]         返回BIO_ctrl(bio,BIO_C_SET_SSL,flag,(char *)ssl);         ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~     SWIG / _m2crypto_wrap.c:7699:19:警告:隐式转换失去整数精度:&#39; unsigned long&#39;到&#39; int&#39; [-Wshorten-64至32]                 err = ERR_get_error();                     〜^ ~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:7751:59:警告:隐式转换失去整数精度:&#39; long&#39;到&#39; int&#39; [-Wshorten-64至32]             ms =((start-&gt; tv_sec +(int)timeout) - tv.tv_sec)* 1000;                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~     SWIG / _m2crypto_wrap.c:7996:19:警告:隐式转换失去整数精度:&#39; unsigned long&#39;到&#39; int&#39; [-Wshorten-64至32]                 err = ERR_get_error();                     〜^ ~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:8026:37:警告:隐式转换失去整数精度:&#39; Py_ssize_t&#39; (又名&#39; long&#39;)到&#39; int&#39; [-Wshorten-64至32]         r = SSL_write(ssl,buf.buf,buf.len);             ~~~~~~~~~~~~~ ^ ~~     SWIG / _m2crypto_wrap.c:8069:37:警告:隐式转换失去整数精度:&#39; Py_ssize_t&#39; (又名&#39; long&#39;)到&#39; int&#39; [-Wshorten-64至32]         r = SSL_write(ssl,buf.buf,buf.len);             ~~~~~~~~~~~~~ ^ ~~     SWIG / _m2crypto_wrap.c:8087:19:警告:隐式转换失去整数精度:&#39; unsigned long&#39;到&#39; int&#39; [-Wshorten-64至32]                 err = ERR_get_error();                     〜^ ~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:8143:12:警告:隐式转换失去整数精度:&#39; long&#39;到&#39; int&#39; [-Wshorten-64至32]         返回SSL_CTX_set_session_cache_mode(ctx,mode);         ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     /usr/local/opt/openssl/include/openssl/ssl.h:2484:9:注意:从宏扩展&#39; SSL_CTX_set_session_cache_mode&#39;             SSL_CTX_ctrl(CTX,SSL_CTRL_SET_SESS_CACHE_MODE,米,NULL)             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~     SWIG / _m2crypto_wrap.c:8148:12:警告:隐式转换失去整数精度:&#39; long&#39;到&#39; int&#39; [-Wshorten-64至32]         return SSL_CTX_get_session_cache_mode(ctx);         ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     /usr/local/opt/openssl/include/openssl/ssl.h:2486:9:注意:从宏扩展&#39; SSL_CTX_get_session_cache_mode&#39;             SSL_CTX_ctrl(CTX,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~     SWIG / _m2crypto_wrap.c:8680:14:警告:隐式转换失去整数精度:&#39; size_t&#39; (又名&#39; unsigned long&#39;)to&#39; int&#39; [-Wshorten-64至32]         outlen = BIO_ctrl_pending(bio);                〜^ ~~~~~~~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:8742:14:警告:隐式转换失去整数精度:&#39; size_t&#39; (又名&#39; unsigned long&#39;)to&#39; int&#39; [-Wshorten-64至32]         outlen = BIO_ctrl_pending(bio);                〜^ ~~~~~~~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:22694:14:警告:隐式转换失去整数精度:&#39; Py_ssize_t&#39; (又名&#39; long&#39;)到&#39; int&#39; [-Wshorten-64至32]           arg4 = len;                〜^ ~~     SWIG / _m2crypto_wrap.c:25282:14:警告:隐式转换失去整数精度:&#39; Py_ssize_t&#39; (又名&#39; long&#39;)到&#39; int&#39; [-Wshorten-64至32]           arg3 = len;                〜^ ~~     产生了21个警告。     SWIG / _m2crypto_wrap.c:2894:9:警告:变量&#39; res&#39;无论何时使用都未初始化,如果&#39;条件是真的[-Wsometimes-uninitialized]         if(PyType_Ready(tp)&lt; 0)             ^ ~~~~~~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:2918:10:注意:此处发生未初始化的使用       返回资源;              ^ ~~     SWIG / _m2crypto_wrap.c:2894:5:注意:删除&#39; if&#39;如果它的条件总是假的         if(PyType_Ready(tp)&lt; 0)         ^ ~~~~~~~~~~~~~~~~~~~~~~~~     SWIG / _m2crypto_wrap.c:2875:10:注意:初始化变量&#39; res&#39;沉默这个警告       int res;              ^               = 0     产生1个警告。     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:警告:忽略文件/usr/local/opt/openssl/lib/libssl.dylib,文件是为x86_64构建的,它不是被链接的体系结构(i386):/ usr / local / opt / openssl / lib / libssl。 dylib     ld:警告:忽略文件/usr/local/opt/openssl/lib/libcrypto.dylib,文件是为x86_64构建的,它不是被链接的体系结构(i386):/ usr / local / opt / openssl / lib / libcrypto。 dylib     运行install_lib     创建/Library/Python/2.7/site-packages/M2Crypto     错误:无法创建&#39; /Library/Python/2.7/site-packages/M2Crypto':权限被拒绝

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

命令&#34; / usr / bin / python -u -c&#34;导入setuptools,tokenize; 文件 =&#39; / private / var / folders / q5 / qk1gf6z15kschmf5dwb3mqvh0000gn /T/pip-build-WeyOs_y/M2crypto/setup.py';f=getattr(tokenize,' open&#39;,open)( file ); code = f。 read()。replace(&#39; \ r \ n&#39;,&#39; \ n&#39;); f.close(); exec(编译(代码,文件, &#39; EXEC&#39;))&#34; install --record /var/folders/q5/qk1gf6z15kschmf5dwb3mqvh0000gn/T/pip-tp6pQY-record/install-record.txt --single-version-external-managed --compile&#34;在/ private / var / folders / q5 / qk1gf6z15kschmf5dwb3mqvh0000gn / T / pip-build-WyOs_y / M2crypto /

中出现错误代码1失败

我最努力的工作。修复最终成为一个简单的chmod sudo: sudo chmod 777 /Library/Python/2.7/site-packages /