简体   繁体   中英

pip dependencies of dependencies when installed from conda environment.yaml

I am trying to create a conda environment.yml file for users of a project. One dependency is not distributed by conda, but available with pip+github. I assume based on this example that I can do this:

dependencies
    - pip
    - regular_conda_dep
    - depend_of_blah
    # Install in editable mode.
    - -e git+https://github.com/ourgroup/blah.git

But what happens to the dependencies of blah (depend_of_blah)? Will the pip install after the conda so that as long as I am careful to include it gets installed before blah? Later on will blah update cleanly, getting as much as possible from conda?

Or do I need to add --no-deps to the pip line? Is it implied that this is done magically? I don't see a lot of advanced examples that deal with this, but in my experience is that it is a real danger in pip/conda mixes not to use --no-deps, with pip essentially hijacking anything that hasn't been explicitly handled first.

Conda parses the YAML, and partitions the dependency specifications into a Conda set and a Pip set ( code ). Only the Conda set is used to solve and create the initial environment. 1 Once the environment has been successfully created, Conda writes all the Pip specifications to a temporary requirements.txt ( code ), and then using the python in the environment runs the command:

python -m pip install -U -r <requirements.txt>

So, to explicitly answer the question: If all the dependencies of blah are installed via Conda and they have sufficient versions installed, then Pip should only install blah and leave the Conda versions untouched. This is because the default value for --upgrade-strategy is only-if-needed .

Otherwise, if the Conda dependencies section does not include all the dependencies of blah , then Pip will install the necessary dependencies.


[1]: Technically, if there are create_default_packages set in the Conda configuration, Conda will first create the environment with just these packages, then subsequently install the dependencies specified in the YAML file.

You can tell pip to ignore dependencies via environment variables

PIP_NO_DEPS=1 conda env create -f myenv.yaml

From the documentation :

pip's command line options can also be set with environment variables using the format PIP_<UPPER_LONG_NAME> . Dashes ( - ) have to be replaced with underscores ( _ ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM