SSL backend error when using OpenSSL

2019-01-13 02:44发布

I was trying to install pycurl in a virtualenv using pip and I got this error

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

I read some documentation saying that "To fix this, you need to tell setup.py what SSL backend is used" (source) although I am not sure how to do this since I installed pycurl using pip.

How can I specify the SSL backend when installing pycurl with pip?

Thanks

21条回答
倾城 Initia
2楼-- · 2019-01-13 03:34

This worked for me:

pip install --compile --install-option="--with-openssl" pycurl

查看更多
Evening l夕情丶
3楼-- · 2019-01-13 03:35

For python 2.7

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

For python 3.5 also install the next:

sudo apt-get install python3.5-dev

Download the latest pycurl-7.43.0.tar.gz (md5) Source from pypi https://pypi.python.org/pypi/pycurl/7.43.0#downloads and run the next command:

python setup.py --with-openssl install

Also you can do it into python environment:

(test_env)user@pc:~/Downloads/pycurl-7.43.0$ python setup.py --with-openssl install
查看更多
Root(大扎)
4楼-- · 2019-01-13 03:37
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

pip install pycurl --global-option="--with-openssl"
查看更多
爷、活的狠高调
5楼-- · 2019-01-13 03:38

This link sums up the reason why the errors occur and gives a clear instruction to fix the problem.

https://cscheng.info/2018/01/26/installing-pycurl-on-macos-high-sierra.html

For me, the problem occurred when I upgraded to High-Sierra from El Captain.

查看更多
三岁会撩人
6楼-- · 2019-01-13 03:39

I had this problem for days. Finally with the help of other answers here (mainly Alexander Tyapkov's) I got it working for AWS Elastic Beanstalk.

Manual install (connecting with SSH):

sudo pip uninstall pycurl
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
sudo pip install pycurl-7.43.0.tar.gz --global-option="--with-nss"

IMPORTANT: Please note that you have to make sure you are using the currect version of Python and PIP, otherwise you might be compiling it for Python 2.x and using v3.x.

Auto-install in Elastic Beanstalk:

files:
  "/usr/local/share/pycurl-7.43.0.tar.gz" :
    mode: "000644"
    owner: root
    group: root
    source: https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz

commands:
  01_download_pip3:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'curl -O https://bootstrap.pypa.io/get-pip.py'
  02_install_pip3:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'python3 get-pip.py'
  03_pycurl_uninstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: '/usr/bin/yes | sudo pip uninstall pycurl'
  04_pycurl_download:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz'
  05_pycurl_reinstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    command: 'sudo pip install pycurl-7.43.0.tar.gz --global-option="--with-nss"'

container_commands:
  09_pycurl_reinstall:
    # run this before PIP installs requirements as it needs to be compiled with OpenSSL
    # the upgrade option is because it will run after PIP installs the requirements.txt file.
    # and it needs to be done with the virtual-env activated
    command: 'source /opt/python/run/venv/bin/activate && pip3 install /usr/local/share/pycurl-7.43.0.tar.gz --global-option="--with-nss" --upgrade'

I had this problem because I was trying to configure Celery 4 with Django 1.10 in Elastic Beanstalk. If that's your case, I wrote a full blog post about it.

查看更多
孤傲高冷的网名
7楼-- · 2019-01-13 03:40

I am running this on OS X and some of the above solutions weren't working. Similar to Edward Newell's comment the PYCURL_SSL_LIBRARY variable seemed to have been completely ignored.
Further reading of the PycURL installation doc revealed the following:

pip may reinstall the package it has previously compiled instead of recompiling pycurl with newly specified options

Therefore, I had to force it to compile with:

pip install --compile pycurl

That works on a number of cases. However, I did run into a few systems that continued to ignore the variable so, similar to maharg101's answer, I resorted to the install options which through pip can be set like this:

pip install pycurl --global-option="--with-[ssl|gnutls|nss]"

where you select one of the three options inside the square brackets. Notice that the available option is ssl and not openssl. If you specify --with-openssl you'll get an error. Also note that if you were messing around with the PYCURL_SSL_LIBRARY variable and switching it to funky values to see what would happen this last command will definitely catch it and throw an error if the value is set but not valid.

查看更多
登录 后发表回答