折腾:
【未解决】Mac中启动PySpider
期间,去尝试从源码编译安装pycurl时,报错了:
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/opt/openssl/include;pip install pycurl --compile --no-cache-dir Collecting pycurl Downloading https://files.pythonhosted.org/packages/ef/05/4b773f74f830a90a326b06f9b24e65506302ab049e825a3c0b60b1a6e26a/pycurl-7.43.0.5.tar.gz (216kB) 100% |████████████████████████████████| 225kB 1.7MB/s Installing collected packages: pycurl Running setup.py install for pycurl ... error Complete output from command /Users/xxx/.pyenv/versions/3.6.8/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/pip-install-42eq60t9/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/pip-record-02wut96c/install-record.txt --single-version-externally-managed --compile: Using curl-config (libcurl 7.54.0) Using SSL library: OpenSSL/LibreSSL/BoringSSL running install running build running build_py creating build creating build/lib.macosx-10.14-x86_64-3.6 creating build/lib.macosx-10.14-x86_64-3.6/curl copying python/curl/__init__.py -> build/lib.macosx-10.14-x86_64-3.6/curl running build_ext building 'pycurl' extension creating build/temp.macosx-10.14-x86_64-3.6 creating build/temp.macosx-10.14-x86_64-3.6/src clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/openssl/include -DPYCURL_VERSION="7.43.0.5" -DHAVE_CURL_SSL=1 -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_SSL=1 -I/Users/xxx/.pyenv/versions/3.6.8/include/python3.6m -c src/docstrings.c -o build/temp.macosx-10.14-x86_64-3.6/src/docstrings.o In file included from src/docstrings.c:4: src/pycurl.h:165:13: fatal error: 'openssl/ssl.h' file not found # include <openssl/ssl.h> ^~~~~~~~~~~~~~~ 1 error generated. error: command 'clang' failed with exit status 1 ---------------------------------------- Command "/Users/xxx/.pyenv/versions/3.6.8/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/pip-install-42eq60t9/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/pip-record-02wut96c/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/pip-install-42eq60t9/pycurl/
搜:
‘openssl/ssl.h’ file not found
pycurl ‘openssl/ssl.h’ file not found
去试试:
brew install openssl Updating Homebrew... Error: openssl@1.1 1.1.1d is already installed To upgrade to 1.1.1g, run `brew upgrade openssl@1.1`
已安装了。
brew info openssl openssl@1.1: stable 1.1.1g (bottled) [keg-only] Cryptography and SSL/TLS Toolkit https://openssl.org/ /usr/local/Cellar/openssl@1.1/1.1.1d (7,983 files, 17.9MB) Poured from bottle on 2019-11-01 at 11:50:22 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb License: OpenSSL ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. ==> Analytics install: 595,026 (30 days), 1,985,779 (90 days), 6,696,740 (365 days) install-on-request: 71,954 (30 days), 265,896 (90 days), 863,719 (365 days) build-error: 0 (30 days)
看起来是安装到了:
/usr/local/Cellar/openssl@1.1/1.1.1d
去看看
open /usr/local/Cellar/openssl@1.1/1.1.1d
是否有对应头文件:

是有的。
以及确认:
ll /usr/local/opt/openssl/include ls: /usr/local/opt/openssl/include: No such file or directory
之前传入的路径不存在。
所以去加上对应路径
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/Cellar/openssl@1.1/1.1.1d;pip install pycurl --compile --no-cache-dir
好像搞错了,少加了个include
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/Cellar/openssl@1.1/1.1.1d/include;pip install pycurl --compile --no-cache-dir
即可成功安装:
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/Cellar/openssl@1.1/1.1.1d/include;pip install pycurl --compile --no-cache-dir Collecting pycurl Downloading https://files.pythonhosted.org/packages/ef/05/4b773f74f830a90a326b06f9b24e65506302ab049e825a3c0b60b1a6e26a/pycurl-7.43.0.5.tar.gz (216kB) 100% |████████████████████████████████| 225kB 1.3MB/s Installing collected packages: pycurl Running setup.py install for pycurl ... done Successfully installed pycurl-7.43.0.5

【总结】
此处Mac中之前已用brew安装过openssl,但是此处
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/opt/openssl/include;pip install pycurl --compile --no-cache-dir
报错:
In file included from src/docstrings.c:4: src/pycurl.h:165:13: fatal error: 'openssl/ssl.h' file not found # include <openssl/ssl.h>
直接原因:找不到openssl/ssl.h
根本原因:但实际上已安装了openssl,是有openssl/ssl.h的。只是传入的路径不对。
解决办法:找到已安装的openssl的实际路径,传入正确的路径。
步骤:
找到已安装的openssl的实际安装路径
brew info openssl
可以看到有:
/usr/local/Cellar/openssl@1.1/1.1.1d (7,983 files, 17.9MB)
其中的:
/usr/local/Cellar/openssl@1.1/1.1.1d
就是我们要的,此处openssl的实际安装路径
通过
open /usr/local/Cellar/openssl@1.1/1.1.1d
确认是有对应的:
/usr/local/Cellar/openssl@1.1/1.1.1d/include/openssl/ssl.h
这个文件的。
所以传入路径应该改为:
/usr/local/Cellar/openssl@1.1/1.1.1d/include
完整命令是:
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/Cellar/openssl@1.1/1.1.1d/include;pip install pycurl --compile --no-cache-dir
即可。
转载请注明:在路上 » 【已解决】Mac中pip安装pycurl报错:fatal error openssl/ssl.h file not found