Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

pip - How to automatically install the most common python packages?

I'm getting tired or installing the same 20 or 30 python packages all the time. Is there an off the shelf way to batch install all the most common python tools in one go? I know I can write my own bash script, but I would prefer something curated that I don't have to maintain by myself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Automatically install the most common packages? No.*

  • * (I suppose someone could write a script which checks pypi's stats and downloads & installs them but you'd still need to run the script for each fresh install.)

Semi-Automatically install a certain set of packages? Yes.

  1. Make a new folder and create a file called requirements.txt (or anything you prefer).
  2. In it, list all the packages you want.
    • Start with those 20-30 packages you mentioned, perhaps with version numbers.
    • Details on the format of the file here.
  3. Then run python -m pip download -r requirements.txt.
    • This will only download the packages to the current folder, not install them.
  4. Copy that folder to a USB drive
  5. for each new Python install, open a command prompt, go to the folder and type python -m pip install -r requirements.txt.
  6. You could even put those two commands in separate batch (.bat) files or shell scripts. So you can just 'double-click' them to execute.
  7. And once a week, or whatever cycle you like, run the first command to get the latest versions and then run the command: python -m pip install --upgrade -r requirements.txt.

(Another option):

  • Copy-paste a long command like python -m pip install package1 package2 package3 ... packageN for each new install.

PS. You almost never actually need all those many packages, and should use a Virtual Env per project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...