mamba icon indicating copy to clipboard operation
mamba copied to clipboard

mamba env create doesn't respect pip constraints file

Open mieczyslaw opened this issue 2 years ago • 5 comments

Troubleshooting docs

  • [X] My problem is not solved in the Troubleshooting docs

How did you install Mamba?

Mambaforge

Search tried in issue tracker

pip constraints

Latest version of Mamba

  • [X] My problem is not solved with the latest version

Tried in Conda?

I have this problem with Conda as well, without using Mamba

Describe your issue

See the attached dummy package: mydummyproject_mamba.tar.gz

When I run mamba env create --prefix .venv -f environment.yml, it installs numpy 1.26.0 (the newest one) - it does not respect that in constraints file I ask for numpy 1.25.0. If I then activate the env and uninstall numpy, then call pip install -e . --constraint constraint.txt, the version in constraints is installed. The correct version is also installed if pure virtualenv is used. The issue is both with mamba and conda. I believe the issue may have been introduced quite recently.

mamba info / micromamba info

mamba version : 1.4.9
     active environment : base
            shell level : 1
          conda version : 23.7.3
    conda-build version : 3.24.0
         python version : 3.10.10.final.0
       virtual packages : __archspec=1=x86_64
                          __osx=13.5.2=0
                          __unix=0=0
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
               platform : osx-64
             user-agent : conda/23.7.3 requests/2.28.2 CPython/3.10.10 Darwin/22.6.0 OSX/13.5.2
                UID:GID : 503:20
             netrc file : None
           offline mode : False

Logs

No response

environment.yml

channels:
  - conda-forge
  - nodefaults
dependencies:
- python=3.11
- pip>=21.0
- pip:
  - -e . --constraint constraint.txt

~/.condarc

No response

mieczyslaw avatar Sep 29 '23 09:09 mieczyslaw

Sorry but this isn't supported by Conda or Mamba yet, and I don't think it will ever be.

jonashaag avatar Sep 29 '23 09:09 jonashaag

Thanks @jonashaag for a quick reply. Could you explain to me how execution of env.yml line:

- pip:
  - -e . --constraint constraint.txt

is different from calling pip install -e . --constraint constraint.txt

in the activated env?

Does mamba env create remove --constraint parameter from this line when executing it? This is a pretty standard line in env.yml to install package from sources.

mieczyslaw avatar Sep 29 '23 09:09 mieczyslaw

Sorry I didn't read the original message properly.

Can you try to debug this further eg by increasing the log level? I think we are passing the parameters unmodified

jonashaag avatar Sep 29 '23 13:09 jonashaag

I attached the .tar.gz and commands so you can try as well. If I run with -vv, I see that pip command is (I removed full paths):

['/mydummyproject/.venv/bin/python', '-m', 'pip', 'install', '-U', '-r', '/mydummyproject/condaenv.7gyh7kly.requirements.txt', '--exists-action=b']
Pip subprocess output:

Collecting numpy (from mydummyproject==0.1.0->-r /mydummyproject/condaenv.7gyh7kly.requirements.txt (line 1))
  Obtaining dependency information for numpy from https://files.pythonhosted.org/packages/d2/2f/b42860931c1479714201495ffe47d74460a916ae426a21fc9b68c5e329aa/numpy-1.26.0-cp311-cp311-macosx_10_9_x86_64.whl.metadata
  Using cached numpy-1.26.0-cp311-cp311-macosx_10_9_x86_64.whl.metadata (53 kB)

So it seems to use -r and req file - it seems to see line 1 there. I can't see this file as it is removed after installation.

It looks to me that mamba env create skips --constraint/-c, as per pip install docs:

 -r, --requirement <file>    Install from the given requirements file. This option can be used multiple times.
 -c, --constraint <file>     Constrain versions using the given constraints file. This option can be used multiple times.

so versions are skipped. I suppose it ignores --constraint completely and prepares new requirements file based on setup.cfg? (without versions unless pinned in setup.cfg/setup.py)?

Anyway, is there any way to keep this --constraint if present in pip section of environment.yml?

mieczyslaw avatar Sep 29 '23 14:09 mieczyslaw

Hi. Is there any work planned to repair this issue?

mieczyslaw avatar Jul 20 '24 08:07 mieczyslaw

I can successfully create your environment as for 2.0.5.

In particular, the specification in the pip: section is correctly forwarded to pip and the following command is executed:

pip -e . --constraint constraint.txt
mamba create -n repro -f env.yaml
conda-forge/noarch                                  18.9MB @   1.4MB/s 13.8s
conda-forge/linux-64                                41.6MB @   1.7MB/s 24.5s


Transaction

  Prefix: repro

  Updating specs:

   - python=3.11
   - pip>=21.0
   - pip


  Package               Version  Build               Channel           Size
─────────────────────────────────────────────────────────────────────────────
  Install:
─────────────────────────────────────────────────────────────────────────────

  + _libgcc_mutex           0.1  conda_forge         conda-forge     Cached
  + _openmp_mutex           4.5  2_gnu               conda-forge     Cached
  + bzip2                 1.0.8  h4bc722e_7          conda-forge     Cached
  + ca-certificates   2025.1.31  hbcca054_0          conda-forge      158kB
  + ld_impl_linux-64       2.43  h712a8e2_2          conda-forge     Cached
  + libexpat              2.6.4  h5888daf_0          conda-forge     Cached
  + libffi                3.4.2  h7f98852_5          conda-forge     Cached
  + libgcc               14.2.0  h77fa898_1          conda-forge     Cached
  + libgcc-ng            14.2.0  h69a702a_1          conda-forge     Cached
  + libgomp              14.2.0  h77fa898_1          conda-forge     Cached
  + liblzma               5.6.3  hb9d3cd8_1          conda-forge     Cached
  + libnsl                2.0.1  hd590300_0          conda-forge     Cached
  + libsqlite            3.48.0  hee588c1_1          conda-forge     Cached
  + libuuid              2.38.1  h0b41bf4_0          conda-forge     Cached
  + libxcrypt            4.4.36  hd590300_1          conda-forge     Cached
  + libzlib               1.3.1  hb9d3cd8_2          conda-forge     Cached
  + ncurses                 6.5  h2d0b736_3          conda-forge     Cached
  + openssl               3.4.0  h7b32b05_1          conda-forge     Cached
  + pip                    25.0  pyh8b19718_0        conda-forge     Cached
  + python              3.11.11  h9e4cc4f_1_cpython  conda-forge       31MB
  + readline                8.2  h8228510_1          conda-forge     Cached
  + setuptools           75.8.0  pyhff2d567_0        conda-forge     Cached
  + tk                   8.6.13  noxft_h4845f30_101  conda-forge     Cached
  + tzdata                2025a  h78e105d_0          conda-forge     Cached
  + wheel                0.45.1  pyhd8ed1ab_1        conda-forge     Cached

  Summary:

  Install: 25 packages

  Total download: 31MB

─────────────────────────────────────────────────────────────────────────────


Confirm changes: [Y/n] Y

Transaction starting
ca-certificates                                    158.1kB @ 159.7kB/s  0.8s
python                                              30.6MB @   2.2MB/s 13.9s
Linking _libgcc_mutex-0.1-conda_forge
Linking ld_impl_linux-64-2.43-h712a8e2_2
Linking ca-certificates-2025.1.31-hbcca054_0
Linking libgomp-14.2.0-h77fa898_1
Linking _openmp_mutex-4.5-2_gnu
Linking libgcc-14.2.0-h77fa898_1
Linking openssl-3.4.0-h7b32b05_1
Linking libzlib-1.3.1-hb9d3cd8_2
Linking liblzma-5.6.3-hb9d3cd8_1
Linking ncurses-6.5-h2d0b736_3
Linking libgcc-ng-14.2.0-h69a702a_1
Linking libexpat-2.6.4-h5888daf_0
Linking libsqlite-3.48.0-hee588c1_1
Linking libffi-3.4.2-h7f98852_5
Linking tk-8.6.13-noxft_h4845f30_101
Linking libxcrypt-4.4.36-hd590300_1
Linking bzip2-1.0.8-h4bc722e_7
Linking readline-8.2-h8228510_1
Linking libuuid-2.38.1-h0b41bf4_0
Linking libnsl-2.0.1-hd590300_0
Linking tzdata-2025a-h78e105d_0
Linking python-3.11.11-h9e4cc4f_1_cpython
Linking wheel-0.45.1-pyhd8ed1ab_1
Linking setuptools-75.8.0-pyhff2d567_0
Linking pip-25.0-pyh8b19718_0

Transaction finished

To activate this environment, use:

    mamba activate repro

Or to execute a single command in this environment, use:

    mamba run -n repro mycommand

warning  libmamba You are using 'pip' as an additional package manager.
    Be aware that packages installed with 'pip' are managed independently from 'conda-forge' channel.

Installing pip packages: -e . --constraint constraint.txt
  DEPRECATION: Legacy editable install of mydummyproject==0.1.0 from file:///tmp/mydummyproject_mamba/mydummyproject (from -r /tmp/mydummyproject_mamba/mydummyproject/mambafxlskpzzek4 (line 1)) (setup.py develop) is deprecated. pip 25.1 will enforce this behaviour change. A possible replacement is to add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information. Discussion can be found at https://github.com/pypa/pip/issues/11457

jjerphan avatar Jan 31 '25 11:01 jjerphan