conda / conda-lock

Lightweight lockfile for conda environments
https://conda.github.io/conda-lock/
Other
456 stars 101 forks source link

Error on python 3.12 due to missing `distutils` within vendored conda #607

Closed wholtz closed 4 months ago

wholtz commented 4 months ago

Checklist

What happened?

This is similar to #542 but the stack trace is different, so I believe it will require a different fix.

$ conda-lock lock -f environment.yaml
Traceback (most recent call last):
  File "/Users/willholtz/.local/bin/conda-lock", line 5, in <module>
    from conda_lock import main
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/__init__.py", line 3, in <module>
    from conda_lock.conda_lock import main
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/conda_lock.py", line 50, in <module>
    from conda_lock.conda_solver import solve_conda
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/conda_solver.py", line 19, in <module>
    from conda_lock.interfaces.vendored_conda import MatchSpec
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/interfaces/vendored_conda.py", line 2, in <module>
    from conda_lock._vendor.conda.models.match_spec import MatchSpec
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/_vendor/conda/models/match_spec.py", line 20, in <module>
    from .channel import Channel
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/_vendor/conda/models/channel.py", line 17, in <module>
    from ..base.context import context, Context
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/_vendor/conda/base/context.py", line 55, in <module>
    from ..common.configuration import (Configuration, ConfigurationLoadError, MapParameter,
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/_vendor/conda/common/configuration.py", line 41, in <module>
    from .path import expand
  File "/Users/willholtz/.local/pipx/venvs/conda-lock/lib/python3.12/site-packages/conda_lock/_vendor/conda/common/path.py", line 21, in <module>
    from distutils.spawn import find_executable
ModuleNotFoundError: No module named 'distutils'

Conda Info

I only have micromamba installed - no conda or mamba:

$ micromamba info

       libmamba version : 1.5.6
     micromamba version : 1.5.6
           curl version : libcurl/8.5.0 SecureTransport (OpenSSL/3.2.0) zlib/1.2.13 zstd/1.5.5 libssh2/1.11.0 nghttp2/1.58.0
     libarchive version : libarchive 3.7.2 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.5
       envs directories : /Users/willholtz/micromamba/envs
          package cache : /Users/willholtz/micromamba/pkgs
                          /Users/willholtz/.mamba/pkgs
            environment : None (not found)
           env location : -
      user config files : /Users/willholtz/.mambarc
 populated config files :
       virtual packages : __unix=0=0
                          __osx=14.3=0
                          __archspec=1=arm64
               channels :
       base environment : /Users/willholtz/micromamba
               platform : osx-arm64

Conda Config

$ micromamba  config sources
Configuration files (by precedence order):

Conda list

$ micromamba list
List of packages in environment: ""

Additional Context

When I using python 3.11 the error does not occur.

maresb commented 4 months ago

Do you have a MWE environment.yaml you could share?

wholtz commented 4 months ago

Seems to give the error on any environment I throw at it. But here is a specific one:

environment.yaml:

name: base
platforms:
  - linux-64
channels:
  - conda-forge
dependencies:
  - jq
maresb commented 4 months ago

I'm unable to reproduce this. Any ideas?

$ docker run --rm -it mambaorg/micromamba
$ cat >> environment.yml
name: base
platforms:
  - linux-64
channels:
  - conda-forge
dependencies:
  - jq
$ micromamba install -y -c conda-forge conda-lock && conda-lock
...
Locking dependencies for ['linux-64']...
INFO:conda_lock.conda_solver:linux-64 using specs ['jq']
 - Install lock using: conda-lock install --name YOURENV conda-lock.yml
maresb commented 4 months ago

It's weird. The test suite has lots of holes which I'm slowly trying to get patched, but a bunch of stuff is tested, and it passes under Python 3.12.

wholtz commented 4 months ago

I also do not get the error while running within a mambaorg/micromamba container. When I get the error, I'm using python v3.12.1 installed via pyenv (so built locally). And for completeness, this is with an Apple M2 CPU.

maresb commented 4 months ago

Interesting. Would you be able to make a Dockerfile for it?

wholtz commented 4 months ago

I have not yet ventured into the world of macos native containers. I'll look into it.

Are you aware of this? https://docs.python.org/dev/whatsnew/3.12.html#:~:text=PEP%20632%3A%20Remove,activated%20virtual%20environment.

Maybe python3.12 from conda-forge is automatically pulling in Setuptools?

maresb commented 4 months ago

How convinced are you that it's a mac thing?

Setuptools is a really great hypothesis. Does it work if you install setuptools in your env? Maybe we just need an explicit setuptools dependency? That would be a very easy fix.

wholtz commented 4 months ago

I'm not convinced it is a mac thing. I'll try adding Setuptools in a few hours. Need to head out right now.

wholtz commented 4 months ago

Thanks! 2.5.5 did fix it for me.