简体   繁体   English

无法在 MacOs 中为 python2 安装 pyopenssl

[英]Unable to install pyopenssl in MacOs for python2

I'm trying to run scrapy command with this in python2.7 in Mac OS:我正在尝试在 Mac OS 的 python2.7 中使用此运行 scrapy 命令:

cmdline.execute("scrapy crawl pornHubSpider".split())

But i'm receiving this error:但我收到此错误:

from OpenSSL._util import lib as pyOpenSSLlib
ImportError: No module named _util

When I try to install当我尝试安装时

sudo pip install pyopenssl --user --upgrade

I get:我得到:

build/temp.macosx-10.13-intel-2.7/_openssl.c:493:10: fatal error: 'openssl/opensslv.h' file not found
    #include <openssl/opensslv.h>
             ^~~~~~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'cc' failed with exit status 1

    ----------------------------------------
    Command "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-v_oSaa/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-A590v3-record/install-record.txt --single-version-externally-managed --compile --user" failed with error code 1 in /private/tmp/pip-build-v_oSaa/cryptography

How can I fix this?我怎样才能解决这个问题?

You are either missing or using an older version of openssl package or using an older version of pip.您丢失或使用了旧版本的 openssl 包或使用旧版本的 pip。

  1. In your terminal, do openssl version .在您的终端中,执行openssl version If it is installed, do brew upgrade openssl .如果已安装,请执行brew upgrade openssl If not installed, do brew install openssl如果未安装,请执行brew install openssl
  2. Update pip - pip install -U upgrade if you are not using the latest version.如果您使用的不是最新版本, pip install -U upgrade更新 pip - pip install -U upgrade
  3. Install pyopenssl using pip install pyopenssl .使用安装pyopenssl pip install pyopenssl If properly installed, skip step 4.如果安装正确,请跳过步骤 4。
  4. Install pyopenssl package using使用pyopenssl安装包
    pip install pyopenssl --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include"

Reference: https://github.com/pyca/cryptography/issues/3489参考: https : //github.com/pyca/cryptography/issues/3489

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM