Under WSL2 running Ubuntu 20.04 I've tried to install virtualenv with pip running pip install virtualenv
but the command just hangs printing nothing.
I terminated it and ran it again with python3 -v -m pip install virtualenv
as advised here and it hangs on import 'keyring.backends.OS_X'
line:
[...]
# /usr/lib/python3/dist-packages/keyring/backends/__pycache__/_OS_X_API.cpython-38.pyc matches /usr/lib/python3/dist-packages/keyring/backends/_OS_X_API.py
# code object from '/usr/lib/python3/dist-packages/keyring/backends/__pycache__/_OS_X_API.cpython-38.pyc'
# destroy keyring.backends._OS_X_API
import 'keyring.backends.OS_X' # <_frozen_importlib_external.SourceFileLoader object at 0x7fa66c4b4610>
I've tried running python -m pip install some_package_you_want
as answered here but the same problem occurs.
Also, I've tried exporting PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
environment variable as advised here but unfortunately it did not solve the problem either.
EDIT: The python3 -v -m pip install virtualenv
command eventually succeeded after hanging for about 5 minutes.
EDIT2: I think the problem is with the WSL2 being too slow as commented here. Eventually I've installed the virtualenv (venv) with sudo apt-get install python3-venv
and activated the virtual environment with python3 -v -m venv venv
command and the similar hang problem occurred now on the line import 'argparse' # <_frozen_importlib_external.SourceFileLoader object at 0x7ff1bc5f1c40>
hanging here for about 2 minutes. This supports the WSL2 slowness problem.
Is the DISPLAY
environment variable set? If so, clearing it first before running pip worked for me:
export DISPLAY=
pip install <packagename>
(Or, as a one-liner: DISPLAY= pip install <packagename>
)
I traced the problem on my system down to this line:
import keyring
Importing keyring
taking very long in WSL2 is an already known problem, that has been fixed in keyring versions ≥ 21.6.0.
Therefore, updating keyring
to the latest version should solve the problem:
pip install -U keyring
or rather
DISPLAY= pip install -U keyring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With