Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Python dependency packages from requirements.txt using conda.
#
# Original solution via StackOverflow:
# http://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t
#
#
# Install via `conda` directly.
# This will fail to install all
# dependencies. If one fails,
# all dependencies will fail to install.
#
conda install --yes --file requirements.txt
#
# To go around issue above, one can
# iterate over all lines in the
# requirements.txt file.
#
while read requirement; do conda install --yes $requirement; done < requirements.txt
@brando90

This comment has been minimized.

Show comment
Hide comment
@brando90

brando90 Oct 7, 2017

why do u need the second one?

brando90 commented Oct 7, 2017

why do u need the second one?

@soultemptation

This comment has been minimized.

Show comment
Hide comment
@soultemptation

soultemptation Dec 13, 2017

What do you mean with the "second one"? The second command? The second parameter?
Why line 19 is used is described in the comments above it.

What do you mean with the "second one"? The second command? The second parameter?
Why line 19 is used is described in the comments above it.

@draskell

This comment has been minimized.

Show comment
Hide comment
@draskell

draskell Dec 28, 2017

This is really useful, I have recently found out about the environment.yml approach for managing dependencies with conda through a stack overflow question: here. I'm wondering if you could expand this script to create an environment yaml or write out a pip-requirements.txt file as it goes through the lines?

One suggested improvement was to catch the errors:
while read requirement; do conda install --yes $requirement; done < requirements.txt 2>error.log

This is really useful, I have recently found out about the environment.yml approach for managing dependencies with conda through a stack overflow question: here. I'm wondering if you could expand this script to create an environment yaml or write out a pip-requirements.txt file as it goes through the lines?

One suggested improvement was to catch the errors:
while read requirement; do conda install --yes $requirement; done < requirements.txt 2>error.log

@aleksod

This comment has been minimized.

Show comment
Hide comment
@aleksod

aleksod Jan 25, 2018

This is great! Thank you!

aleksod commented Jan 25, 2018

This is great! Thank you!

@git-sohib

This comment has been minimized.

Show comment
Hide comment
@git-sohib

git-sohib Mar 24, 2018

I am in the conda env and the conda install --yes --file requirements.txt failed. Now, here you gave a solution: while read requirement; do conda install --yes $requirement; done < requirements.txt

Where is that snippet inserted? Should I change requirements.txt file or what?

I am a windows user btw

git-sohib commented Mar 24, 2018

I am in the conda env and the conda install --yes --file requirements.txt failed. Now, here you gave a solution: while read requirement; do conda install --yes $requirement; done < requirements.txt

Where is that snippet inserted? Should I change requirements.txt file or what?

I am a windows user btw

@No-Stream

This comment has been minimized.

Show comment
Hide comment
@No-Stream

No-Stream May 1, 2018

@git-sohib you just run that from your directory that contains the requirements.txt file. (If it's not named requirements.txt, you can change the filename in that command.)

Note that the command installs packages one at a time, so it's a bit slower than batch installing, but it doesn't fail if Conda encounters some errors. (For instance, if a package isn't available as a Conda package, then the install fails.) You may want to try the simpler conda install --yes --file requirements.txt if you expect the packages to be available.

@git-sohib you just run that from your directory that contains the requirements.txt file. (If it's not named requirements.txt, you can change the filename in that command.)

Note that the command installs packages one at a time, so it's a bit slower than batch installing, but it doesn't fail if Conda encounters some errors. (For instance, if a package isn't available as a Conda package, then the install fails.) You may want to try the simpler conda install --yes --file requirements.txt if you expect the packages to be available.

@dror-kris

This comment has been minimized.

Show comment
Hide comment
@dror-kris

dror-kris May 23, 2018

I'm trying to run the command, but receive the error:
'while' is not recognized as an internal or external command, operable program or batch file

image

What am I missing?

I'm trying to run the command, but receive the error:
'while' is not recognized as an internal or external command, operable program or batch file

image

What am I missing?

@vickylance

This comment has been minimized.

Show comment
Hide comment
@vickylance

vickylance May 30, 2018

@dror-kris That is a sh file meant to run on a linux as a bash script. Not on windows.

@dror-kris That is a sh file meant to run on a linux as a bash script. Not on windows.

@makmanalp

This comment has been minimized.

Show comment
Hide comment
@makmanalp

makmanalp Jun 14, 2018

One potential issue with this is that when you install each package individually, conda won't have a unified view of what version of everything you're installing and whether their subdependencies conflict, so the later packages you install might override things that earlier packages installed (I think?)

One potential issue with this is that when you install each package individually, conda won't have a unified view of what version of everything you're installing and whether their subdependencies conflict, so the later packages you install might override things that earlier packages installed (I think?)

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