Problems installing libraries via pip after installing Python 3.12 [duplicate]
Asked Answered
U

3

12

Today I installed the new Python 3.12 on my Ubuntu 22.04 from the ppa repository ppa:deadsnakes/ppa.

Everything works, but when I try to install some library with the command python3.12 -m pip install somelibrary, I get the following 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'?

Any suggestions why this is happening?

EDIT: This problem doesn't exist when I use venv, it seems to me that the problem is that pip uses /usr/lib/python3 instead of /usr/lib/python3.12

Underskirt answered 5/10, 2023 at 16:10 Comment(6)
Not all modules that were available in 3.11 (and before) are currently available in Python 3.12Angeli
Can reproduce with 3.12.0-1+jammy1 from deadsnakes.Overshine
I edited the question text, have a lookUnderskirt
@DarkKnight Could you clarify what you mean? Are you talking about the fact that distutils was removed from the standard library? Or do you think this has to do with somelibrary not having a 3.12 distribution on PyPI? This does not appear to be the latter, since it's an internal error inside the bundled pipOvershine
@Overshine All I know, as stated, is that some modules (e.g., pyqt5) cannot currently be installed on 3.12. I didn't research exactly why - I just know it doesn't work and that it's something that's being "worked on". It is my suspicion (possibly unfounded) that other modules available through PyPi are not yet 3.12 readyAngeli
Does this answer your question? AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?Redbug
U
9

python3.12 -m ensurepip --upgrade fixed my problem! solution

Underskirt answered 19/1 at 19:38 Comment(2)
ensurepip not found in my case.Marileemarilin
@Marileemarilin same hereEichmann
A
12

Here is what I did:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
Aframe answered 14/10, 2023 at 2:34 Comment(0)
U
9

python3.12 -m ensurepip --upgrade fixed my problem! solution

Underskirt answered 19/1 at 19:38 Comment(2)
ensurepip not found in my case.Marileemarilin
@Marileemarilin same hereEichmann
W
3

After installing python3.12 on Ubuntu 22 via ppa:deadsnakes/ppa I came across the same error.

My issue was caused by just installing python3.12, I needed these packages as well to ensure pip can be used as expected

sudo apt install python3.12-dev 
sudo apt install python3.12-venv
Winters answered 8/8 at 17:16 Comment(1)
Thanks so much! I wasn't previously aware of the python3.12-venv package. After installing that, I ran python3.12 -m venv .venv, which worked for me!Koger

© 2022 - 2024 — McMap. All rights reserved.