简体   繁体   中英

When combining Conda environment files and Pip, is Conda evironment active when Pip install is run?

I am using both pip and conda to install dependencies for my project. I keep dependencies that I wish to install via conda in an environment.yml file and dependencies which I install via pip inside a requirements.txt file (which I reference from inside the environment.yml file). Here is the repo with the actual config files for reference.

From the install logs it appears that conda first runs the command

$ conda env create --prefix ./env --file environment.yml

and the runs the pip install command as a sub-process. However I don't understand from the logs whether or not the environment has been temporarily activated before the pip command is run.

I can explicitly force the desired behavior by running the following commands (after removing the reference to the requirements.txt file inside the environment.yml file)

$ conda env create --prefix ./env --file environment.yml
$ conda activate ./env
$ pip install -r requirements.txt

But I would like to know if this is what already happens "under the hood".

In the environment.yml file itself you can menton the pip packages as well.You don't need to create a seperate requirements.txt file for pip packages.

Usually an environment.yml file contains the following fields:

name : the conda environment name

channels : the channels from which the dependencies needs to be installed

dependencie: : list of package. In that you can mention the pip dependencies as well

For more details, you can refer the following urls:

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-from-file

The pip dependencies will be installed in the conda environment and you don't need to activate the environment and install pip dependencies manually. Command to create conda environment:

conda env create -f environment.yml

Once the above command completes successfully, you can activate the environment and check the installed packages as below:

conda activate <env_name>
conda list

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