pip等同于`npm install package --save-dev`吗? [英] What is pip's equivalent of `npm install package --save-dev`?
问题描述
在nodejs中,我可以执行npm install package --save-dev
将已安装的软件包保存到软件包中.
In nodejs, I can do npm install package --save-dev
to save the installed package into the package.
如何在Python包管理器pip
中实现相同的目的?我想在使用pip install package --save-dev requirements.pip
之类安装软件包后,将软件包名称及其版本保存到requirements.pip
中.
How do I achieve the same thing in Python package manager pip
? I would like to save the package name and its version into, say, requirements.pip
just after installing the package using something like pip install package --save-dev requirements.pip
.
推荐答案
pip
没有等效项.
最好的方法是pip install package && pip freeze > requirements.txt
您可以在其文档页面上看到所有可用的选项.
如果确实让您感到困扰,那么编写一个自定义bash脚本(pips
)并不会太困难,该脚本带有一个-s
参数并自动冻结为您的requirements.txt
文件.
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.
编辑1
自编写此书以来,提供与NPM类似的自动--save-dev
选项没有任何变化,但是Kenneth Reitz(requests
等的作者)已经发布了有关更好的点子工作流程,以更好地处理pip
更新.
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.
编辑2
从上面的更好的点子工作流程"文章链接到现在,建议使用 pipenv
管理需求和虚拟环境.最近使用了很多,我想总结一下过渡是多么简单:
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:
安装pipenv
(在Mac上)
Install pipenv
(on Mac)
brew install pipenv
pipenv
创建并管理它自己的虚拟环境,因此在具有现有requirements.txt
的项目中,安装所有要求(我使用Python3.7,但如果不这样做,则可以删除--three
)是如此简单:
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
激活virtualenv来运行命令也很容易
pipenv shell
安装要求将自动更新Pipfile
和Pipfile.lock
pipenv install <package>
还可以更新过期的软件包
pipenv update
我强烈建议检查出来,尤其是来自npm
背景的人因为它具有与package.json
和package-lock.json
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
这篇关于pip等同于`npm install package --save-dev`吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!