Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
#To export environment file
activate <environment-name>
conda env export > <environment-name>.yml
#For other person to use the environment
conda env create -f <environment-name>.yml
# For Windows users
@hanifa2102
Copy link

hanifa2102 commented Feb 14, 2019

#Remove conda environments
conda env remove -n <env_name>

Duplicate conda environments
conda create --name <clone_name> --clone <env_name>

#List Conda environments
conda env list

@marinagolden
Copy link

marinagolden commented Mar 4, 2019

where does the .yml and .txt file go so i can share with the team and where does the team paste it in?

@bitwerkstatt
Copy link

bitwerkstatt commented Mar 6, 2019

The file is written to the directory where you execute the command. I would recommend to put it in the corresponding project root and add it to git or any other SCM in use.

@neerajvashistha
Copy link

neerajvashistha commented Apr 9, 2019

#Install from .txt file
conda create --name <env_name> --file <.txt file>

@SundeepPidugu
Copy link

SundeepPidugu commented Jun 13, 2019

How to get the list for a specific conda environment ?

@spookyQubit
Copy link

spookyQubit commented Jun 18, 2019

@SundeepPidugu

One way to know the list of packages for a specific conda environment is to follow a two-step process:
conda activate <env_you_are_interested_in> # First activate the environment
conda list # List linked packages in a conda environment. See conda --help | grep list

PS: Will be happy to know if there is an alternate way which does not require to activate the env.

@ikvision
Copy link

ikvision commented Apr 22, 2020

I think that for activating a conda env
conda activate <environment-name>
rather than
activate <environment-name>

@Bigous
Copy link

Bigous commented Jul 15, 2020

@SundeepPidugu

One way to know the list of packages for a specific conda environment is to follow a two-step process:
conda activate <env_you_are_interested_in> # First activate the environment
conda list # List linked packages in a conda environment. See conda --help | grep list

PS: Will be happy to know if there is an alternate way which does not require to activate the env.

conda list -n <environment name>

@JutasiR
Copy link

JutasiR commented Mar 15, 2021

Dear All,

After creation of requirements.txt, I found the list to long, I think Anaconda adds many unnecessary libraries (I guess default ones), not just what I installed (and its dependencies). Am I correct, is there a way to streamline the requirements file? Many thanks!

@pratos
Copy link
Author

pratos commented Mar 16, 2021

The dependent packages will be added to the requirements.txt file hence the bloating of that file. My current advice for everyone is to use poetry for dependency management in a python project (if you aren't using any conda optimized package, then using anaconda/miniconda is your only friend).

You can check out here: https://python-poetry.org/

@Bigous
Copy link

Bigous commented Mar 16, 2021

@JutasiR, conda does not add libraries that you didn't install. The only exception is the base environment.

That's why you should create a new environment for your work and install what you need.

[]'s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment