What is pip's equivalent of `npm install package --save-dev`?

前端 未结 8 1903
生来不讨喜
生来不讨喜 2021-01-29 20:07

In nodejs, I can do npm install package --save-dev to save the installed package into the package.

How do I achieve the same thing in Python package manager

8条回答
  •  情歌与酒
    2021-01-29 21:13

    How about make a shell function to do this ? Add below code to your ~/.profile or ~/.bashrc

    pips() {
        local pkg=$1
    
        if [ -z "$1" ]; then
            echo "usage: pips "
            return 1
        fi
    
        local _ins="pip install $pkg"
        eval $_ins
        pip freeze | grep $pkg -i >> requirements.txt
    }
    

    then run source ~/.profile or source ~/.bashrc to import it to your current terminal

    when you want to install && save a package, just run, for example pips requests. after package was installed, its version will be save into requirements.txt in your current directory.

提交回复
热议问题