-2

i have a problem when i want install a module or package with pip in my wsl!!!

For example, I run this command pip3 install cowsay or pip install cowsay and I get this error:

ERROR: Exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 165, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 285, in run
    session = self.get_default_session(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 75, in get_default_session
    self._session = self.enter_context(self._build_session(options))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 89, in _build_session
    session = PipSession(
              ^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/network/session.py", line 282, in __init__
    self.headers["User-Agent"] = user_agent()
                                 ^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/network/session.py", line 157, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pip/_internal/metadata/__init__.py", line 24, in get_default_environment
    from .pkg_resources import Environment
  File "/usr/lib/python3/dist-packages/pip/_internal/metadata/pkg_resources.py", line 9, in <module>
    from pip._vendor import pkg_resources
  File "/usr/lib/python3/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

Please help me if you can.

3
  • 2
    Try to upgrade pip python -m pip install --upgrade pip
    – 16171413
    Commented Aug 4 at 23:38
  • stackoverflow.com/…
    – phd
    Commented Aug 5 at 8:28
  • when i run this command terminal says: "Defaulting to user installation because normal site-packages is not writeable" Commented Aug 5 at 17:51

1 Answer 1

0

The problem occurs because you are using Python 3.12 in which pkgutil.ImpImporter is deprecated, and your pip version is not the latest.

You can solve the problem by updaing the pip. Here is the command:

python -m ensurepip --upgrade
3
  • when i run this command terminal say: "no module named ensurepip" Commented Aug 5 at 17:44
  • In that case, download the get-pip.py with curl command. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py. After that, run this file with command python get-pip.py to install the latest pip. Commented Aug 6 at 1:23
  • this command didn't work for me:( Commented Aug 17 at 18:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.