adafruit/circup

Python 3.12 does not provide setuptools, and circup needs it

dhalbert opened this issue · 3 comments

I installed circup 1.8.0 in a venv with Python 3.12.3 on Ubuntu 24.04. A Two problem arose:

  1. circup expects setuptools to be installed because it uses pkg_resources. pkg_resources is deprecated. From https://setuptools.pypa.io/en/latest/pkg_resources.html:

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.

2. After installing setuptools to work around problem 1, I got this when trying a simple install:
[deleted; my PATH was wrong]

sjev commented

I've picked up #189 . This one is related. However, I did not encounter issuse in a devcontainer running Python 3.12.3.

pip install . worked without issues. Please provide info on how to reproduce.

@sjev
Here is a reproduction on Ubuntu 24.04, running in a venv named .py. setuptools is installed in the venv, and then I uninstall it:

(.py) halbert@cod:~$ circup list
Found device at /media/halbert/CIRCUITPY, running CircuitPython 9.1.0-beta.1-16-g8734076e04-dirty.
All modules found on the device are up to date.
(.py) halbert@cod:~$ pip list |grep setuptools
setuptools                               69.5.1
(.py) halbert@cod:~$ pip3 uninstall setuptools
Found existing installation: setuptools 69.5.1
Uninstalling setuptools-69.5.1:
  Would remove:
    /home/halbert/.py/lib/python3.12/site-packages/_distutils_hack/*
    /home/halbert/.py/lib/python3.12/site-packages/distutils-precedence.pth
    /home/halbert/.py/lib/python3.12/site-packages/pkg_resources/*
    /home/halbert/.py/lib/python3.12/site-packages/setuptools-69.5.1.dist-info/*
    /home/halbert/.py/lib/python3.12/site-packages/setuptools/*
Proceed (Y/n)? y
  Successfully uninstalled setuptools-69.5.1
(.py) halbert@cod:~$ circup list
Traceback (most recent call last):
  File "/home/halbert/.py/bin/circup", line 5, in <module>
    from circup import main
  File "/home/halbert/.py/lib/python3.12/site-packages/circup/__init__.py", line 9, in <module>
    from circup.shared import DATA_DIR, BAD_FILE_FORMAT, extract_metadata, _get_modules_file
  File "/home/halbert/.py/lib/python3.12/site-packages/circup/shared.py", line 14, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

If you can't reproduce this make sure setuptools has not been installed via apt. E.g. try import setuptools in Python.

sjev commented

@dhalbert Thank you, this is clear. Now I see that I misunderstood the original issue.