最新消息:20190529 VPS服务器已从腾讯云香港换为Vultr新加坡,主题仍用朋友推荐的大前端D8

【已解决】Mac中pipenv中运行PySpider出错:ImportError pycurl libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

Mac crifan 424浏览 0评论

同事的Mac 10.12.6的macOS Sierra系统:

某项目中,安装了pipenv后,去运行pyspider,结果出现之前遇到过的问题:

ImportError pycurl libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

参考之前自己的:

【已解决】pyspider运行出错:ImportError pycurl libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

试了上述的有所的办法,包括:

<code>pipenv shell

pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/opt/openssl/include;pip install pycurl --compile --no-cache-dir
</code>

问题依旧。

然后又去参考了:

mportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other) · Issue #4 · transloadit/python-sdk

<code>pipenv shell

pipenv uninstall pycurl

export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

pip install pycurl --global-option="--with-openssl"
</code>

以及:

<code>brew reinstall openssl
pip uninstall pycurl
pip install --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl" pycurl
</code>

相关log

<code>(xxx_process) bash-3.2$ brew reinstall openssl
==&gt; Reinstalling openssl
==&gt; Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2p.sierra.bottle.tar.gz
Already downloaded: /Users/mac/Library/Caches/Homebrew/downloads/a8e90b7dde6f36b6095c1bda76ddcaafb3993c2899bb2742d4d3c59805690c29--openssl-1.0.2p.sierra.bottle.tar.gz
==&gt; Pouring openssl-1.0.2p.sierra.bottle.tar.gz
==&gt; Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' &gt;&gt; ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

==&gt; Summary
🍺  /usr/local/Cellar/openssl/1.0.2p: 1,793 files, 12.3MB
</code>

以及:

重新安装了Python官网下载的Python 3.6.7,问题依旧。

后来又遇到:

src/pycurl.h:164:13: fatal error: ‘openssl/ssl.h’ file not found

参考自己的:

【已解决】Mac中编译安装pycurl失败:error: command ‘gcc’ failed with exit status 1

发现:

自己之前是:

<code>xx-Pro:~ x$ which openssl
/usr/bin/openssl

xx-Pro:~ x$ openssl version -a
LibreSSL 2.2.7
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx)
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
</code>

此处是:

<code>(xx) bash-3.2$ which openssl
/usr/local/opt/openssl/bin/openssl
(xx) bash-3.2$ openssl version -a
OpenSSL 1.0.2p  14 Aug 2018
built on: reproducible build, date unspecified
platform: darwin64-x86_64-cc
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: clang -I. -I.. -I../include  -fPIC -fno-common -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/local/etc/openssl"
</code>

-》

  • 自己10.13.6的Mac中:

    • openssl路径是:/usr/bin/openssl

    • openssl version中用的库是:LibreSSL 2.2.7

  • 同事的10.12.6的Mac中:

    • openssl路径是:/usr/local/opt/openssl/bin/openssl

    • openssl version中用的库是:OpenSSL 1.0.2p  14 Aug 2018

-》完全不同。

去找了下区别:

tls – What are the main advantages of using LibreSSL in favor of OpenSSL – Information Security Stack Exchange

https://security.stackexchange.com/questions/112545/what-are-the-main-advantages-of-using-libressl-in-favor-of-openssl

解释是:

LibreSSL是基于TLS/crypto栈的,2014年从OpenSSL分出来的版本

LibreSSL有更多优势:

  • 代码架构更加优化

  • 提升了安全性

    • OpenSSL出现过的6个安全漏洞,在LibreSSL中都没有出现

  • 更多最佳实践过程

并且大家采用LibreSSL也更多:

  • OpenBSD中,替代了OpenSSL

  • OS X 10.11之后就换用LibreSSL了

-》结论很明显:

能用LibreSSL就用LibreSSL,尽量不要在用OpenSSL了。

-》所以此处为了解决

ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)

的问题,最好是去升级macOS到最新版本后,再去安装openssl,然后或许问题就可以解决了。

-》结果真的问题就解决了。

-》说明真的是:

【总结】

旧Mac系统 10.12.6中,用brew install openssl时:

https://homebrew.bintray.com/bottles/openssl-1.0.2p.sierra.bottle.tar.gz

-》去下载的是sierra=10.12.6的Mac的openssl

-》其内部用的库是:OpenSSL

而新系统,至少:

我的 10.13.6 macOS High Sierra

和同事升级后的:10.14 macOS Mojave

(参考:

【已解决】Mac中编译安装pycurl失败:error: command ‘gcc’ failed with exit status 1

brew install openssl

安装:

https://homebrew.bintray.com/bottles/openssl-1.0.2p.high_sierra.bottle.tar.gz

的是:high sierra

-》 是10.13.6之后的openssl

-》内部的库是:LibreSSL

-》此时才可以正常使用。

-》后续运行pyspider才正常。

所以此处的解决办法就是:

升级Mac系统到10.13.6 macOS High Sierra(或更新的10.14 macOS Mojave)

转载请注明:在路上 » 【已解决】Mac中pipenv中运行PySpider出错:ImportError pycurl libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
64 queries in 0.093 seconds, using 18.84MB memory