如何使用Python的pip来下载并保存压缩文件的包?

时间:2022-02-03 07:00:34

If I want to use the pip command to download a package (and its dependencies), but keep all of the zipped files that get downloaded (say, django-socialregistration.tar.gz) - is there a way to do that?

如果我想使用pip命令下载一个包(以及它的依赖项),但是要保留所有下载的压缩文件(例如,django-socialregistration.tar.gz)——是否有这样的方法?

I've tried various command-line options, but it always seems to unpack and delete the zipfile - or it gets the zipfile, but only for the original package, not the dependencies.

我尝试过各种命令行选项,但它似乎总是解压并删除zipfile——或者它获得zipfile,但只针对原始包,而不是依赖项。

5 个解决方案

#1


107  

The --download-cache option should do what you want:

下载-缓存选项应该做你想做的:

pip install --download-cache="/pth/to/downloaded/files" package

However, when I tested this, the main package downloaded, saved and installed ok, but the the dependencies were saved with their full url path as the name - a bit annoying, but all the tar.gz files were there.

然而,当我测试这个时,主包被下载、保存并安装了ok,但是依赖项被保存为完整的url路径作为名称——有点烦人,但是所有的tar。gz文件。

The --download option downloads the main package and its dependencies and does not install any of them. (Note that prior to version 1.1 the --download option did not download dependencies.)

下载选项下载主包及其依赖项,不安装它们中的任何一个。(注意,在1.1版之前——下载选项没有下载依赖项。)

pip install package --download="/pth/to/downloaded/files"

The pip documentation outlines using --download for fast & local installs.

pip文档概述了使用——下载快速和本地安装。

#2


48  

I always do this to download the packages:

我总是这样下载包:

pip install --download /path/to/download/to_packagename

pip安装,下载/道路/ /下载/ to_packagename

OR

pip install --download=/path/to/packages/downloaded -r requirements.txt

pip安装——下载=/路径/打包/下载-r requirements.txt。

And when I want to install all of those libraries I just downloaded, I do this:

当我想要安装我刚下载的所有库时,我这样做:

pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename

pip安装——无索引——find-links="/path/to/下载/依赖" packagename。

OR

pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt

pip安装—无索引—查找链接=“/path/到/下载/包”—r requirements.txt


Update

更新

Also, to get all the packages installed on one system, you can export them all to requirement.txt that will be used to intall them on another system, we do this:

另外,要在一个系统上安装所有包,可以将它们全部导出到需求。txt将被用于在另一个系统中整合它们,我们这样做:

pip freeze > requirement.txt

皮普冻结> requirement.txt

Then, the requirement.txt can be used as above for download, or do this to install them from requirement.txt:

然后,要求。txt可以像上面一样用于下载,或者从requirement.txt中安装它们:

pip install -r requirement.txt

pip安装- r requirement.txt

REFERENCE: pip installer

参考:pip安装程序

#3


39  

pip install --download is deprecated. Starting from version 8.0.0 you should use pip download command:

pip安装——不赞成下载。从8.0.0版本开始,您应该使用pip下载命令:

 pip download <package-name>

#4


7  

In version 7.1.2 pip downloads the wheel of a package (if available) with the following:

在7.1.2版本中,pip下载包的*(如果有的话),并附带以下内容:

pip install package -d /path/to/downloaded/file

The following downloads a source distribution:

以下下载一个源发行版:

pip install package -d /path/to/downloaded/file --no-binary :all:

These download the dependencies as well, if pip is aware of them (e.g., if pip show package lists them).

如果pip知道这些依赖项(例如,如果pip show package列出它们),它们也会下载这些依赖项。


Update

更新

As noted by Anton Khodak, pip download command is preferred since version 8. In the above examples this means that /path/to/downloaded/file needs to be given with option -d, so replacing install with download works.

正如Anton Khodak指出的,pip下载命令是首选的,因为版本8。在上面的例子中,这意味着/path/to/download /file需要用选项d提供,所以用download代替install是可行的。

#5


1  

Use pip download <package1 package2 package n> to download all the packages including dependencies

使用pip下载 下载所有包,包括依赖项

Use pip install --no-index --find-links . <package1 package2 package n> to install all the packages including dependencies. It gets all the files from CWD. It will not download anything

使用pip安装——无索引——查找链接。 安装所有包,包括依赖项。它从CWD获取所有的文件。它不会下载任何东西

#1


107  

The --download-cache option should do what you want:

下载-缓存选项应该做你想做的:

pip install --download-cache="/pth/to/downloaded/files" package

However, when I tested this, the main package downloaded, saved and installed ok, but the the dependencies were saved with their full url path as the name - a bit annoying, but all the tar.gz files were there.

然而,当我测试这个时,主包被下载、保存并安装了ok,但是依赖项被保存为完整的url路径作为名称——有点烦人,但是所有的tar。gz文件。

The --download option downloads the main package and its dependencies and does not install any of them. (Note that prior to version 1.1 the --download option did not download dependencies.)

下载选项下载主包及其依赖项,不安装它们中的任何一个。(注意,在1.1版之前——下载选项没有下载依赖项。)

pip install package --download="/pth/to/downloaded/files"

The pip documentation outlines using --download for fast & local installs.

pip文档概述了使用——下载快速和本地安装。

#2


48  

I always do this to download the packages:

我总是这样下载包:

pip install --download /path/to/download/to_packagename

pip安装,下载/道路/ /下载/ to_packagename

OR

pip install --download=/path/to/packages/downloaded -r requirements.txt

pip安装——下载=/路径/打包/下载-r requirements.txt。

And when I want to install all of those libraries I just downloaded, I do this:

当我想要安装我刚下载的所有库时,我这样做:

pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename

pip安装——无索引——find-links="/path/to/下载/依赖" packagename。

OR

pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt

pip安装—无索引—查找链接=“/path/到/下载/包”—r requirements.txt


Update

更新

Also, to get all the packages installed on one system, you can export them all to requirement.txt that will be used to intall them on another system, we do this:

另外,要在一个系统上安装所有包,可以将它们全部导出到需求。txt将被用于在另一个系统中整合它们,我们这样做:

pip freeze > requirement.txt

皮普冻结> requirement.txt

Then, the requirement.txt can be used as above for download, or do this to install them from requirement.txt:

然后,要求。txt可以像上面一样用于下载,或者从requirement.txt中安装它们:

pip install -r requirement.txt

pip安装- r requirement.txt

REFERENCE: pip installer

参考:pip安装程序

#3


39  

pip install --download is deprecated. Starting from version 8.0.0 you should use pip download command:

pip安装——不赞成下载。从8.0.0版本开始,您应该使用pip下载命令:

 pip download <package-name>

#4


7  

In version 7.1.2 pip downloads the wheel of a package (if available) with the following:

在7.1.2版本中,pip下载包的*(如果有的话),并附带以下内容:

pip install package -d /path/to/downloaded/file

The following downloads a source distribution:

以下下载一个源发行版:

pip install package -d /path/to/downloaded/file --no-binary :all:

These download the dependencies as well, if pip is aware of them (e.g., if pip show package lists them).

如果pip知道这些依赖项(例如,如果pip show package列出它们),它们也会下载这些依赖项。


Update

更新

As noted by Anton Khodak, pip download command is preferred since version 8. In the above examples this means that /path/to/downloaded/file needs to be given with option -d, so replacing install with download works.

正如Anton Khodak指出的,pip下载命令是首选的,因为版本8。在上面的例子中,这意味着/path/to/download /file需要用选项d提供,所以用download代替install是可行的。

#5


1  

Use pip download <package1 package2 package n> to download all the packages including dependencies

使用pip下载 下载所有包,包括依赖项

Use pip install --no-index --find-links . <package1 package2 package n> to install all the packages including dependencies. It gets all the files from CWD. It will not download anything

使用pip安装——无索引——查找链接。 安装所有包,包括依赖项。它从CWD获取所有的文件。它不会下载任何东西