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

前端 未结 8 1902
生来不讨喜
生来不讨喜 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:07

    I made a quick hack on pip to add --save option to install/uninstall commands.

    Please have a look at my blog for more information about this hack: http://blog.abhiomkar.in/2015/11/12/pip-save-npm-like-behaviour-to-pip/

    Installation (GitHub): https://github.com/abhiomkar/pip-save

    Hope this helps.

    0 讨论(0)
  • 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 <pkg name>"
            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.

    0 讨论(0)
提交回复
热议问题