pip fails to install pathlib in Ubuntu 22.04 with "setuptools is not available in the build environment"

Bug #1962819 reported by Rocko
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-pip (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

The latest 22.04 updates have broken pathlib. pip complains that setuptools is not available in the build environment even though the package python3-setuptools v59.6.0-1.2 is installed. This breaks any package relying on pathlib.

The output from the install command is:

rocko@ubuntu:~$ pip install pathlib
Defaulting to user installation because normal site-packages is not writeable
Collecting pathlib
  Downloading pathlib-1.0.1.tar.gz (49 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.3/49.3 KB 117.3 kB/s eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: python3-pip 22.0.2+dfsg-1
ProcVersionSignature: Ubuntu 5.15.0-18.18-generic 5.15.12
Uname: Linux 5.15.0-18-generic x86_64
ApportVersion: 2.20.11-0ubuntu78
Architecture: amd64
CasperMD5CheckResult: pass
Date: Thu Mar 3 15:13:02 2022
InstallationDate: Installed on 2021-09-28 (156 days ago)
InstallationMedia: Ubuntu 21.10 "Impish Indri" - Beta amd64 (20210924)
PackageArchitecture: all
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
RebootRequiredPkgs: Error: path contained symlinks.
SourcePackage: python-pip
UpgradeStatus: Upgraded to jammy on 2022-02-18 (12 days ago)

Revision history for this message
Rocko (rockorequin) wrote :
Revision history for this message
Rocko (rockorequin) wrote :

Importing setuptools in a python interpreter works fine:

rocko@ubuntu:~$ python3
Python 3.10.2 (main, Feb 26 2022, 08:21:15) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> try:
... import setuptools
... print('ok')
... except ImportError as error:
... print('failed')
...
ok
>>>

But this same code fails when pip tries to install pathlib:

rocko@ubuntu:~$ pip -v install pathlib
Using pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
Defaulting to user installation because normal site-packages is not writeable
Collecting pathlib
  Using cached pathlib-1.0.1.tar.gz (49 kB)
  Running command python setup.py egg_info
  ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /usr/bin/python3 -c '
  exec(compile('"'"''"'"''"'"'
  # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
  #
  # - It imports setuptools before invoking setup.py, to enable projects that directly
  # import from `distutils.core` to work with newer packaging standards.
  # - It provides a clear error message when setuptools is not installed.
  # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so
  # setuptools doesn'"'"'t think the script is `-c`. This avoids the following warning:
  # manifest_maker: standard file '"'"'-c'"'"' not found".
  # - It generates a shim setup.py, for handling setup.cfg-only projects.
  import os, sys, tokenize

  try:
      import setuptools
  except ImportError as error:
      print(
          "ERROR: Can not execute `setup.py` since setuptools is not available in "
          "the build environment.",
          file=sys.stderr,
      )
      sys.exit(1)

  __file__ = %r

Revision history for this message
Stefano Rivera (stefanor) wrote :

> The latest 22.04 updates have broken pathlib.

If you're referring to a bug in the Debian-packaged python3-pathlib, unrelated to the pip issue described, then please expand on that. If there's a problem in pathlib we should get that fixed, ASAP. Currently there are no open bugs filed against pathlib: https://bugs.launchpad.net/ubuntu/+source/python-pathlib

I can confirm the pip bug, thanks. In Debian I can reproduce it with python 3.10, but not 3.9.

Changed in python-pip (Ubuntu):
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Stefano Rivera (stefanor) wrote :

And.... no, this is a bug in pathlib itself, not pip or python3.10 in debian:

root@warm-bird:/tmp/pathlib-1.0.1# python3
Python 3.10.2 (main, Feb 26 2022, 08:21:15) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/pathlib-1.0.1/pathlib.py", line 10, in <module>
    from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

See the deprecation notice on:
https://pypi.org/project/pathlib/

The pathlib PyPI package hasn't been ported to Python 3.10. It masks the pathlib stdlib module, imported by setuptools, and so blows up pip.

Use pathlib2 instead.

Changed in python-pip (Ubuntu):
status: Confirmed → Invalid
importance: High → Undecided
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.