apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.33k stars 627 forks source link

Python 3.12 Support #2129

Open snej opened 7 months ago

snej commented 7 months ago

🐞Describing the bug

(coremltools-env) $  pip install -U coremltools
Collecting coremltools
  Downloading coremltools-7.1.tar.gz (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 6.2 MB/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
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/7d/hl3k4nxj5_72y9dcxt0brwwm0000gp/T/pip-install-te23914i/coremltools_7669cbec5c1f436d949cfe9db26f0157/setup.py", line 8, in <module>
          import imp
      ModuleNotFoundError: No module named 'imp'
      [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.

Stack Trace

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/7d/hl3k4nxj5_72y9dcxt0brwwm0000gp/T/pip-install-te23914i/coremltools_7669cbec5c1f436d949cfe9db26f0157/setup.py", line 8, in <module>
          import imp
      ModuleNotFoundError: No module named 'imp'

System environment (please complete the following information):

snej commented 7 months ago

I'm not a Python expert, but I looked up the module imp and it's been deprecated since Python 3.4, and no longer exists at all in the Python 3.12.1 that Conda installed.

(coremltools-env) $  python --version
Python 3.12.1
(coremltools-env) $  python
Python 3.12.1 | packaged by Anaconda, Inc. | (main, Jan 19 2024, 09:45:58) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import imp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'imp'
TobyRoseman commented 7 months ago

We don't support Python 3.12 yet. That is the root cause here.

Related to #1846

snej commented 7 months ago

I was able to work around the problem by running conda install python=3.11 -- after that, installing coremltools ran successfully.

snej commented 7 months ago

If this is considered an enhancement, then the bug is on the Installing CoreML Tools web page -- it should tell people to run conda install python=3.11 before installing coremltools. Otherwise anyone following the directions on that web page is going to run into the same problem I did. Is there a separate repo for the docs where this bug can be filed?

TobyRoseman commented 7 months ago

@snej - Right at the top of the document you reference, it says:

The current version of coremltools  includes wheels for Python 3.7, 3.8, 3.9, 3.10, and 3.11.
johnnynunez commented 6 months ago

tensorflow 2.16.1 is out supporting 3.12

teelrabbit commented 6 months ago

This was addressed in https://github.com/apple/coremltools/pull/2170 @YifanShenSZ

TobyRoseman commented 4 months ago

This was addressed in #2170 @YifanShenSZ

There are several other things that need to be addressed before we can support Python 3.12. At a minimum, we still need to update all of our test dependencies to versions that support Python 3.12