79

I use virtualenv to create a python virtual environment for my python project.

#command
pwd
#result
/home/dhanusha/Documents/projects/my-project

# command
virtualenv --version
# results
virtualenv 20.10.0 from /usr/local/lib/python3.8/dist-packages/virtualenv/__init__.py

I tried to create a virtual python3.10 environment using the following command. I could create venv successfully.

# creating venv
virtualenv -p /usr/bin/python3.10 venv

# then, I could activate the `venv` environment successfully using the following command.
source venv/local/bin/activate

# after activation python version shows:
python -V
# results
Python 3.10.1

# after activation pip version shows:
pip -V
#results
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

But when run pip list command, it shows an error:

(venv) dhanusha@dhanusha-pc:~/Documents/projects/my-project$ pip list
Traceback (most recent call last):
  File "/home/dhanusha/Documents/projects/my-project/venv/local/bin/pip", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 13, in <module>
    from pip._internal.cli.req_command import IndexGroupCommand
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 15, in <module>
    from pip._internal.index.package_finder import PackageFinder
  File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21, in <module>
    from pip._internal.index.collector import parse_links
  File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 12, in <module>
    from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
(venv) dhanusha@dhanusha-pc:~/Documents/projects/my-project$ 

For your information:
OS: Ubuntu 20.04 LTS
Python -V command: Python 3.8.10
python3.10 -V command: Python 3.10.1

How can I solve this issue? Thanks in advance.

Dhanusha_Perera07
  • 3,347
  • 5
  • 14
  • 22

1 Answers1

222

If you have faced this error please refer to this answer. In order to save your time, I will post what I have done to solve the issue.

Install the latest pip with the following command:

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
Dhanusha_Perera07
  • 3,347
  • 5
  • 14
  • 22