ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3
Asked Answered
C

15

134

After pip install openai, when I try to import openai, it shows this error:

the 'ssl' module of urllib3 is compile with LibreSSL not OpenSSL

I just followed a tutorial on a project about using API of OpenAI. But when I get to the first step which is the install and import OpenAI, I got stuck. And I tried to find the solution for this error but I found nothing.

Here is the message after I try to import OpenAI:

Python 3.9.6 (default, Mar 10 2023, 20:16:38)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import openai

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yule/Library/Python/3.9/lib/python/site-packages/openai/__init__.py", line 19, in <module>
    from openai.api_resources import (
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/__init__.py", line 1, in <module>
    from openai.api_resources.audio import Audio  # noqa: F401
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/audio.py", line 4, in <module>
    from openai import api_requestor, util
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_requestor.py", line 22, in <module>
    import requests
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py", line 38, in <module>
    raise ImportError(
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/2168

I tried to --upgrade the urllib3, but it is still not working. The result is:

pip3 install --upgrade urllib3
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in ./Library/Python/3.9/lib/python/site-packages (2.0.2)
Cyler answered 6/5, 2023 at 5:11 Comment(2)
Is this a Mac-specific problem? Should the question be or not? "darwin" (and to some degree "clang") hints at macOS.Titled
A commenter has observed the problem on AWS Linux. There are also reports for RHEL and Ubuntu.Titled
A
208

The reason why the error message mentioned OpenSSL 1.1.1+ and LibreSSL 2.8.3 is that urllib3 v2.0 (the version you've installed) requires OpenSSL 1.1.1+ to work properly, as it relies on some new features of OpenSSL 1.1.1.

The issue is that the version of the 'ssl' module that is currently installed in your environment is compiled with LibreSSL 2.8.3, which is not compatible with urllib3 v2.0.

To use urllib3 v2.0, you need an 'ssl' module compiled with OpenSSL 1.1.1 or later, by trying:

brew install [email protected]

Or you could use an older version of urllib3 that is compatible suc. For example urllib3 v1.26.6, which does not have a strict OpenSSL version requirement. You can force the version installing with this command:

pip install urllib3==1.26.6
Apothegm answered 6/5, 2023 at 6:12 Comment(16)
Unfortunately, the installation of [email protected] did not solve the problem for me. Downgrading urllib3 did the job, but this feels a bit awkward.Congius
@KristianHeitkamp Can you tell us which version solved your problem?Bowdlerize
Agreed; I had to do both.Underthrust
Sorry, that I have been so unspecific, I ment the second of the above mentioned solutions: pip install urllib3==1.26.6Congius
It was to correct urllib3 v2.0 (installed with Python 3.9.6)Apothegm
pip install urllib3==1.26.6 has worked in my case. I had urlib3 2+ version earlier which was the causing the issue. Downgrading does resolve the error.Catchword
I think the issue with just installing openssl 1.1 is that the python ssl module still isn't going to be compiled against it. So you'd have to compile python from source against openssl 1.1 after installing openssl 1.1.Stets
I agreed with @KristianHeitkamp, I uninstalled urllib3 and "pip install urllib3==1.26.6" resolved the problem. Only brew install [email protected] would not change the urllib's properties, would still get the same. LibreSSL is OS X default dependent library of SSL. Can see it from linkSchoolteacher
install the eariler urllib version worked for me.Cyler
Answer is recommending brew when question says nothing about being Mac-specific. I'm seeing this error on AWS Linux. Downgrading pip package is not ideal as some packages require newer urllib3 and keep updating it after my downgrade. Curious what Linux options there are, esp. for those w/o root access. Tried installing from source (e.g., help.dreamhost.com/hc/en-us/articles/…) but make test failed.Hydrochloride
What is "compatible suc"?Titled
FWIW the official recommendation is to use 'urllib3<2.0' instead of a specific version like1.26.6: github.com/urllib3/urllib3/issues/3020#issuecomment-1557516332Nilson
Funny why lower versions of softwares can work.Hyperextension
Had to downgrade for it to work.Subcutaneous
I am using urllib3==1.26.16 and getting this error on Amazon Linux on AWS.General
Be aware that mac can host multiple python instances, I was mistakenly using the pre-installed one (under /user/bin). Switching to the python under brew and using brew install [email protected] solved the issue for me (I'm on Mac M1 with macOS 13.6)Arriola
V
140

I had the same issue while working on a MacBook Air (M1). This did the trick for me

pip uninstall urllib3
pip install 'urllib3<2.0'
Valdes answered 26/5, 2023 at 23:31 Comment(7)
This solution works on M2Marcellusmarcelo
@Marcellusmarcelo does it? I am trying to make this work long ago but still having trouble. Any recommentdation ?Compliment
Worked for RHEL7.9 as well. ThanksAbamp
Also work on my ubuntuColic
worked fine on MacOSBlowsy
In my case the problem was that I was unconsciously using the pre-installed python under /usr/bin, so the brew install [email protected] was not affecting that instance.Arriola
Same problem here (Mac M3 on OSX Sonoma), the 1.26.6 urllib3 workedSosthena
G
14

For me, the following worked in PyCharm:

  1. At the bottom right: click on Python 3.*
  2. Interpreter Settings
  3. Double click on the left version of urllib3
  4. Check specify version
  5. and finally select 1.26.18 and Install package
Greathearted answered 10/7, 2023 at 14:57 Comment(0)
C
10

You can try installing an older version of urllib3 that is compatible with the currently installed version of OpenSSL. To do this, you can use pip to install a specific version:

sudo python3.8 -m pip install urllib3==1.26.6
Cyanate answered 20/7, 2023 at 16:11 Comment(2)
pip install urllib3==1.26.6 would be sufficient.Putter
thanks @deadfish, this resolved the issue. I'm getting this particular warning while fetching the data from py5paisa package and trying to get and preprocess it using pandas.Archi
H
9

This worked for me:

$ pip uninstall urllib3
$ pip install urllib3==1.26.7
Human answered 9/1 at 23:14 Comment(1)
Downgrading to 1.26.7 as you suggested helped! 👍Mosby
M
8

I met this problem too. My old version is Python 3.9. "brew install [email protected]" doesn't work for me.

You can try:

pipenv install --python 3.11

That fixed my problem.

Moravia answered 16/5, 2023 at 21:30 Comment(1)
What if this was a lambda function instead ?Trichomoniasis
A
3

On my mac, my version is Python 3.9.6. this is worked for me :

pip3 install urllib3==1.26.6

Here is an explanation of the reason behind this issue: https://github.com/urllib3/urllib3/issues/3020

Alvord answered 12/12, 2023 at 5:33 Comment(1)
To avoid link rot, it's good to directly include the supporting information from a linked source.Lindgren
B
2

We ran into this problem and there were two problems:

  • The urllib3 version is not compatible. -> We removed the current version and tried to install urllib3==1.26.15

Then we ran into the second problem we can't install this version. And we found out Mac Mini uses Z shell (zsh) which didn't allow us to completely install this version of urllib3. We changed to Bash to install and then came back to Z shell. Everything works.

Bandolier answered 1/6, 2023 at 23:11 Comment(1)
Re "Mac Mini uses Z shell": That is dependent on the version of macOS. Z shell is the default shell in macOS v10.15 (Catalina) and later.Titled
E
1

I faced this issue when I tried using Aider.

Below are the steps I followed, which worked for me:

  • pip3 uninstall urllib3 This uninstalled the urllib3 version that came along with aider
  • pip3 install urllib3 This installed the latest version of urllib3
Engrossment answered 14/11, 2023 at 11:55 Comment(0)
A
0

MacPorts version 3.9 compiled with OpenSSL and works properly. Install MacPorts and use Python from it. It is working on my M2.

Python 3.9 (MacPorts package)

Aulea answered 2/6, 2023 at 10:31 Comment(0)
K
0

This is because of a dependency mismatch. Let's say, you have installed a Python package called 'x', and it depends on urllib3. As you may know, urllib3 depends on OpenSSL. Something like this.

x > urllib3 > openssl

When you install x using pip, it will install all x's dependencies, including urllib3. If the installed urllib3 version doesn't support the OpenSSL version, you will get this error.

To fix this, you may downgrade x until this error is fixed.

I found this solution from here.

Koby answered 30/7, 2023 at 1:29 Comment(0)
P
0

On my Mac, this is how the problem is resolved for me:

  1. download the Python interpreter (3.9.6) from https://www.python.org/downloads/macos/ This package includes its own private copy of OpenSSL 1.1.1.

  2. run command "Update Shell Profile.command" from your new Python installation. In my case "/Applications/Python 3.9/Update Shell Profile.command"

Now you can use interpreter in /usr/local/bin/python3

Paper answered 19/8, 2023 at 21:47 Comment(0)
T
0

On my mac, the Python version (2.7) used by Jupyter Notebook was not compliant with urllib3. I was not aware since Python 3.9.18 was also installed.

Long story short, using the following scripts provided here, I adjusted the Jupyter kernel properly. That resolved the error above.

python3 --version
python3 -m pip install ipykernel
python3 -m ipykernel install --user

This would be an empty Python3 environment, and when you need to install the required packages for your script, use the following script rather than simple pip install to be sure that you install the package to the right Python environment.

python3 -m pip install <package_name>
Tighten answered 13/9, 2023 at 15:4 Comment(0)
F
0

For poetry, note that:

  • if you've got a global poetry installation (you should have), then simply running pip install urllib3==1.26.6 won't work, because it won't update the poetry installation. You need to use poetry self, to update the poetry global installation

  • so run:

    poetry self add urllib3==1.26.6

Fantastically answered 24/12, 2023 at 9:7 Comment(0)
A
-1

You should upgrade your system's LibreSSL version. Use brew upgrade [email protected].

Apish answered 6/5, 2023 at 5:26 Comment(2)
On Mac, presumably?Titled
Yes, Brew is a Mac thing (brew.sh). This answer doesn't help other OSs. This did not resolve the issue for me.Bobbie

© 2022 - 2024 — McMap. All rights reserved.