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
There isn't an equivalent with pip
.
Best way is to pip install package && pip freeze > requirements.txt
You can see all the available options on their documentation page.
If it really bothers you, it wouldn't be too difficult to write a custom bash script (pips
) that takes a -s
argument and freezes to your requirements.txt
file automatically.
Edit 1
Since writing this there has been no change in providing an auto --save-dev
option similar to NPM however Kenneth Reitz (author of requests
and many more) has released some more info about a better pip workflow to better handle pip
updates.
Edit 2
Linked from the "better pip workflow" article above it is now recommended to use pipenv to manage requirements and virtual environments. Having used this a lot recently I would like to summarise how simple the transition is:
Install pipenv
(on Mac)
brew install pipenv
pipenv
creates and manages it's own virtual environments so in a project with an existing requirements.txt
, installing all requirements (I use Python3.7 but you can remove the --three
if you do not) is as simple as:
pipenv --three install
Activating the virtualenv to run commands is also easy
pipenv shell
Installing requirements will automatically update the Pipfile
and Pipfile.lock
pipenv install
It's also possible to update out-of-date packages
pipenv update
I highly recommend checking it out especially if coming from a npm
background as it has a similar feel to package.json
and package-lock.json