I would like to install all available modules for Python 2.7.12 using a single pip command. Is there a way to do this without having to specify every single package name?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
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.
You then install it with
pip install -r requirements.txt
and it installs all the packages for your project.This has several benefits:
However, if you really do want to install ALL python packages (note that there are thousands), you can do so via the following:
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).
This is a terrible idea, but you could always use autoinstaller, which will automatically download packages via
pip
if you don't have them installed.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. 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.
Well, I did find a way to do this, but only for the 1000 most popular packages at http://packages.pypy.org. 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. And I did do this on windows using the Command Prompt.
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. 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), typedownloads:\s+\d+
in theSearch for
field, make sure there is no text in theReplace with
field, and leave all the other options at their defaults, clickReplace all
(assuming the program has this button). After that, you get rid of the trailing spaces by doing another replace with a space in theSearch for
field (Python package names do not have spaces). 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 (i.e. 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:
[If Command Prompt can't find the right pip to use, then you need to type the full path to pip e.g. C:\Python27\Scripts\pip.exe]
Voila, pip is now installing all of the packages listed on the link I gave.
You should redirect stdout (and maybe stderr too) to a file because command prompts don't have a large history buffer. For that, you put something like this at the end of the command:
Be careful about abruptly interrupting pip if you use this, because output no longer goes to the terminal. 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.There are quite a number of
and using pip to install these will fail unless you do some additional work. But this should work for the majority of packages.