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`