Skip to content

Instantly share code, notes, and snippets.

@abmohan
Last active November 14, 2020 01:59
Show Gist options
  • Save abmohan/b92a9f2316557598951a11089e727a45 to your computer and use it in GitHub Desktop.
Save abmohan/b92a9f2316557598951a11089e727a45 to your computer and use it in GitHub Desktop.
pip install and save dependencies (i.e. Python equivalent of `npm install --save`)
# pip install and save to (and sort + dedupe) requirements.txt
function pip-save {
# loop through all listed requirements
for var in "$@"
do
# attempt to install it
pip install $var
# add it to the requirements.txt file
pip freeze | grep -i "^$var=" >> requirements.txt
done
# sort requirements.txt and remove duplicates
sort -u requirements.txt -o requirements.txt
}
@moracabanas
Copy link

Good tip. You should take a look on Poetry as an easy npm like python all-in-one environment/dependencies manager.
It is great and so easy to use. Forget requirements.txt, conda, pipenv and messing your python environment.

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