简体   繁体   English

有没有办法使用pip一次安装所有python模块?

[英]Is there a way to install all python modules at once using pip?

I would like to install all available modules for Python 2.7.12 using a single pip command. 我想使用单个pip命令安装Python 2.7.12的所有可用模块。 Is there a way to do this without having to specify every single package name? 有没有办法在不必指定每个包名的情况下执行此操作?

I highly recommend against doing this - the overwhelmingly supported best practice is to use a requirements.txt file, listing the packages you want to install specifically. 我强烈建议不要这样做 - 绝大多数支持的最佳做法是使用requirements.txt文件,列出您要专门安装的软件包。

You then install it with pip install -r requirements.txt and it installs all the packages for your project. 然后使用pip install -r requirements.txt安装它,并安装项目的所有软件包。

This has several benefits: 这有几个好处:

  • Repeatability by installing only the required packages 通过仅安装所需的包来实现可重复性
  • Conciseness 简明

However, if you really do want to install ALL python packages (note that there are thousands ), you can do so via the following: 不过,如果你确实想安装所有的Python包(注意,有数以千计的 ),您可以通过以下操作:

pip search * | 点子搜索* | grep ")[[:space:]]" | grep“)[[:space:]]”| cut -f1 -d" " cut -f1 -d“”

I strongly recommend against this as it's likely to do horrible things to your system, as it will attempt to install every python package (and why it's in spoiler tags). 我强烈建议不要这样做,因为它可能会对你的系统做一些可怕的事情,因为它会尝试安装每个python包 (以及为什么它在扰流标签中)。

这是一个糟糕的主意,但您可以随时使用autoinstaller ,如果您没有安装它们,它将自动通过pip下载软件包。

UPDATE: The other answers were right when they said that this was a terrible idea: Some of the packages I have installed using this method will not work because their fixed-old required dependencies have been updated by other packages. 更新:其他答案正确的,当他们说这是一个可怕的想法:我使用此方法安装的一些软件包将无法工作,因为其他软件包已更新其固定旧的必需依赖项。 Next time, I'm using virtualenv. 下一次,我正在使用virtualenv。 Some day, I'm going to produce a list of packages from packages.pypy.org with their dependencies, so that someone can make many environments with those packages quickly. 有一天,我将从packages.pypy.org生成一个包含其依赖项的包列表,以便有人可以快速创建包含这些包的许多环境。


Well, I did find a way to do this, but only for the 1000 most popular packages at http://packages.pypy.org . 好吧,我确实找到了一种方法来做到这一点,但仅限于http://packages.pypy.org上 1000个最受欢迎的软件包。 But other pages can be processed too, it just needs some creativity. 但其他页面也可以处理,只需要一些创造力。 For that page you will need a spreadsheet program to process tha page. 对于该页面,您需要一个电子表格程序来处理该页面。 I used LibreOffice Calc. 我使用了LibreOffice Calc。 And I did do this on windows using the Command Prompt. 我使用命令提示符在Windows上执行此操作。

First, open the link I just posted and select/copy all the text (and do not expand any of the package names on the webpage). 首先,打开我刚刚发布的链接并选择/复制所有文本(并且不要展开网页上的任何包名称)。

Then, paste it on any cell in Calc. 然后,将其粘贴到Calc中的任何单元格上。 Open the Find & Replace dialog. 打开“查找和替换”对话框。 If you use another spreadsheet program, make sure it's Find & Replace supports regexps. 如果您使用其他电子表格程序,请确保它的查找和替换支持正则表达式。 Select the checkbox next to Regular Expressions (or something like that), type downloads:\\s+\\d+ in the Search for field, make sure there is no text in the Replace with field, and leave all the other options at their defaults, click Replace all (assuming the program has this button). 选中Regular Expressions旁边的复选框(或类似名称),在Search for字段中键入downloads:\\s+\\d+ ,确保Replace with字段中没有文本,并将所有其他选项保留为默认值,单击Replace all (假设程序有此按钮)。 After that, you get rid of the trailing spaces by doing another replace with a space in the Search for field (Python package names do not have spaces). 之后,通过在Search for字段中用空格替换另一个替换来删除尾随空格(Python包名称没有空格)。 Once you do these two replaces, you have a package name in each cell. 完成这两次替换后,每个单元格中都有一个包名称。

Then you copy the entire spreadsheet into a text editor, any editor should work (I used Notepad). 然后将整个电子表格复制到文本编辑器中,任何编辑器都应该工作(我使用记事本)。 The text editor will put the contents of each cell (ie the package names) onto it's own line. 文本编辑器将每个单元格的内容(即包名称)放在它自己的行上。 There won't be any blank lines in the file (but it doesn't hurt to check). 文件中不会有任何空白行(但检查没有坏处)。 At this point you can close the spreadsheet, you don't have to save it's data. 此时您可以关闭电子表格,而不必保存它的数据。

Now save the text file. 现在保存文本文件。 Open a command prompt and change to the folder where you saved the text file. 打开命令提示符并切换到保存文本文件的文件夹。 Now type: 现在输入:

for /F %p in ('type TEXT_FILE_NAME.txt') DO pip.exe install %p

[If Command Prompt can't find the right pip to use, then you need to type the full path to pip eg C:\\Python27\\Scripts\\pip.exe] [如果命令提示符找不到要使用的正确点,那么你需要输入pip的完整路径,例如C:\\ Python27 \\ Scripts \\ pip.exe]

Voila, pip is now installing all of the packages listed on the link I gave. Voila,pip现在正在安装我给出的链接上列出的所有软件包。

You should redirect stdout (and maybe stderr too) to a file because command prompts don't have a large history buffer. 您应该将stdout(也可能是stderr)重定向到文件,因为命令提示没有大的历史记录缓冲区。 For that, you put something like this at the end of the command: 为此,你在命令的末尾加上这样的东西:

>>PIP_STDOUT_FILE.txt 2>>PIP_STDERR_FILE.txt

Be careful about abruptly interrupting pip if you use this, because output no longer goes to the terminal. 如果你使用它,要小心突然中断pip,因为输出不再进入终端。 You might kill it in the middle of a package installation. 您可能会在程序包安装过程中将其终止。 In particular, if you use a text editor to view the output, reload the file frequently. 特别是,如果使用文本编辑器查看输出,请经常重新加载文件。 It's safer to append --log LOG_FILE.txt instead of the above, but the log file becomes more verbose and also writes its messages to the command prompt as usual. 附加--log LOG_FILE.txt而不是上述内容更安全,但日志文件变得更加冗长,并且像往常一样将其消息写入命令提示符。

There are quite a number of 有很多

  1. Linux-only packages 仅限Linux的软件包
  2. Packages built with a Microsoft C++ compiler 使用Microsoft C ++编译器构建的包

and using pip to install these will fail unless you do some additional work. 除非你做一些额外的工作,否则使用pip来安装它们会失败。 But this should work for the majority of packages. 但这适用于大多数包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM