Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by William Boman for Install a package and write to requirements.txt with pip

I've written the following bash function which I use;

function pip-save() {    for pkg in $@; do        pip install "$pkg"&& {            name="$(pip show "$pkg" | grep Name: | awk '{print $2}')";            version="$(pip show "$pkg" | grep Version: | awk '{print $2}')";            echo "${name}==${version}">> requirements.txt;        }    done}

This saves the canonical package name to requirements, as well as the version installed. Example usage;

$ pip-save channels asgi_redis# will save the following to requirements.txt (as of writing):# ---# channels==1.0.1# asgi-redis==1.0.0# ---# note how asgi_redis is translated to its canonical name `asgi-redis`

Viewing all articles
Browse latest Browse all 4

Trending Articles