Pip Error
AttributeError
when checking Pip3 Version
I encountered this issue when trying to check the Python3 and Pip3 version installed in my WSL2 Ubuntu:
$ python3 --version
Python 3.8.10
$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip3')()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
......
The specific error was:
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_NOTIFY_POLICY'
This error comes from the pyOpenSSL
library and indicates a mismatch between the pyOpenSSL
Python package and the underlying libssl
C library.
Problem: Likely due to conflicting or outdated system packages in the WSL Ubuntu environment. This is causing pip3
to crash with an AttributeError
.
Solution: Reinstall pip
using get-pip.py
.
-
Remove broken pip.
sudo apt remove python3-pip -y
-
Manually install pip via get-pip.py. Note that you might encounter an issue if you're running a different Python3 version.
curl -sS https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --userFor example, I was running Python 3.8 but the script above is specific to Python 3.9. As a workaround, download the script for your Python version.
curl -O https://bootstrap.pypa.io/pip/3.8/get-pip.py
python3 get-pip.py --user -
Ensure
~/.local/bin
is in your PATH.echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc -
Verify pip works.
pip3 --version