Open up your .zshrc
or .bashrc
file and paste the following into the bottom:
# 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
}
Now you can do: pip-save django psycopg2-binary
and get an updated requirements.txt
with a locked in version, and move on with what you actually set out to do.
After almost a decade as Node.js developer, I’m back in Python land.
One immediate pet peeve when spinning up new services was how much more typing and copy/pasting I was doing to install dependencies.
Installing a JS dependency (e.g. express and mongoose):
npm install --save express mongoose
#programming #flask #python #python3 #django