简体   繁体   English

如何自动安装最常见的 python 包?

[英]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.我一直在安装相同的 20 或 30 个 python 包,我感到很累。 Is there an off the shelf way to batch install all the most common python tools in one go?是否有现成的方法可以在一个 go 中批量安装所有最常见的 python 工具? I know I can write my own bash script, but I would prefer something curated that I don't have to maintain by myself.我知道我可以编写自己的 bash 脚本,但我更喜欢无需自己维护的策划。

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.) *(我想有人可以编写一个脚本来检查 pypi 的统计信息并下载和安装它们,但您仍然需要为每次全新安装运行该脚本。)

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).创建一个新文件夹并创建一个名为requirements.txt的文件(或任何您喜欢的文件)。
  2. In it, list all the packages you want.在其中,列出您想要的所有包。
  3. Then run python -m pip download -r requirements.txt .然后运行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将该文件夹复制到 USB 驱动器
  5. for each new Python install, open a command prompt, go to the folder and type python -m pip install -r requirements.txt . 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.您甚至可以将这两个命令放在单独的批处理 ( .bat ) 文件或 shell 脚本中。 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 .每周一次,或者您喜欢的任何周期,运行第一个命令以获取最新版本,然后运行命令: 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.对于每个新安装,复制粘贴一个长命令,例如python -m pip install package1 package2 package3... packageN

PS. PS。 You almost never actually need all those many packages, and should use a Virtual Env per project.你几乎从不需要这么多包,每个项目都应该使用一个虚拟环境

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

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