背景
既存コードでpycurl(python2.7上で)を利用しており、チェック用にローカルPC(mac)にpycurlを入れようとして苦労したのでメモ
環境
mac 10.12.6 (Sierra) ※アップデートが許されないので古いまま
python 2.7.10
pip 18.1
pycurl 7.43.0
pycurl インストール 失敗時
$ pip install pycurl
Collecting pycurl
- 中略 -
/urllib3/util/ssl_.py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
Using cached https://files.pythonhosted.org/packages/e8/e4/0dbb8735407189f00b33d84122b9be52c790c7c3b25286826f4e1bdb7bde/pycurl-7.43.0.2.tar.gz
Complete output from command python setup.py egg_info:
Using curl-config (libcurl 7.54.0)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/hl/59yqlmb5165_w2f5c60m2y5r2cn7ty/T/pip-install-zInAm0/pycurl/setup.py", line 913, in <module>
ext = get_extension(sys.argv, split_extension_source=split_extension_source)
File "/private/var/folders/hl/59yqlmb5165_w2f5c60m2y5r2cn7ty/T/pip-install-zInAm0/pycurl/setup.py", line 582, in get_extension
ext_config = ExtensionConfiguration(argv)
File "/private/var/folders/hl/59yqlmb5165_w2f5c60m2y5r2cn7ty/T/pip-install-zInAm0/pycurl/setup.py", line 99, in __init__
self.configure()
File "/private/var/folders/hl/59yqlmb5165_w2f5c60m2y5r2cn7ty/T/pip-install-zInAm0/pycurl/setup.py", line 316, in configure_unix
specify the SSL backend manually.''')
__main__.ConfigurationError: Curl is configured to use SSL, but we have not been able to determine which SSL backend it is using. Please see PycURL documentation for how to specify the SSL backend manually.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/hl/59yqlmb5165_w2f5c60m2y5r2cn7ty/T/pip-install-zInAm0/pycurl/
/lib/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecurePlatformWarning
curl をopenssl指定でインストール
$ brew install curl --with-openssl
SSLのパスをチェック
$ brew link openssl
- 中略 -
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"
pycurl をpipからインストール
$ pip install pycurl==7.43.0 --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include"
インストール成功
$ pip list | grep pycurl
pycurl 7.43.0
importエラーも起きない
$ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
>>>
参考
- Installing PycURL on macOS High Sierra
- ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other) #4