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

前端 未结 8 1985
生来不讨喜
生来不讨喜 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 20:58

    This simple line is a starting point. You can easily built a bash command to reuse the PACKAGE in the line.

    pip install PACKAGE && pip freeze | grep PACKAGE >> requirements.txt
    

    Thanks to @devsnd for the simple bash function example:

    function pip-install-save { 
        pip install $1 && pip freeze | grep $1 >> requirements.txt
    }
    

    To use it, just run:

    pip-install-save some-package
    

提交回复
热议问题