Python:我应该脱机保存PYPI软件包吗?

发布于 2025-01-28 14:28:30 字数 479 浏览 4 评论 0 原文

我的Python项目在很大程度上取决于PYPI软件包
我想确保:将来的任何时间:我的应用所需的包装将始终在PYPI上在线提供。
例如: -
我在GitHub上找到了一个需要Pyqt4的项目。
当我尝试在Linux机器上运行它时,
它在启动上崩溃了,因为它在PYPI上找不到PYQT4软件包。

nb:我知道pyqt4已弃用

我搜索了很多东西,以找到仍然包含PYQT4软件包的PYPI的档案,但是我找不到任何地方


我只更改了与UI相关的代码(IE:PYQT4)。
其他功能仍在工作。

因此,该应用程序的唯一问题是从PYPI中删除了PYQT4软件包。



so, my question is: should I save a backup of the PyPi packages I use ?

My Python projects heavily depends on PyPi packages.
I want to make sure that: in any time in the future: the packages required by my apps will always be available online on PyPi.
For example:-
I found a project on Github that requires PyQt4.
when I tried to run it on my Linux machine,
it crashed on startup because it can't find PyQt4 package on PyPi.

NB: I know that PyQt4 is deprecated

I searched a lot to find an archive for PyPi that still holds PyQt4 package, but I couldn't find them anywhere.

so I had to rewrite that app to make it work on PyQt5.
I only changed the code related to the UI (ie: PyQt4).
other functions were still working.

so the only problem with that app was that PyQt4 package was removed from PyPi.


so, my question is: should I save a backup of the PyPi packages I use ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2025-02-04 14:28:30

简短版本:

是的,如果您想要可用性...下一个大问题是 如何最好地保留依赖关系的备份版本?这个答案结束时有一些建议。

长版本:

您的问题涉及“可用性”的概念,这是信息保证(或信息安全性)的三个支柱之一。其他两个支柱是机密和诚信……中央情报局三合会。

PYPI软件包由这些软件包的所有者维护,该项目取决于软件包并将其列出为依赖项,必须考虑到包装所有者将包裹或包装版本从PYPI中拉出PYPI的可能性任何时刻。

具有许多依赖关系的重要python软件包通常由基础或组织负责处理下游依赖的软件包和项目的组织。但是,保持对旧软件包的支持非常昂贵,需要额外的努力,并且通常维护者设定了支持的日期,或者发布包裹生命周期的日期,他们在其中声明何时将从公共PYPI服务器中删除特定版本。

一旦发生这种情况,受抚养人就必须更新其代码(就像您一样),或者通过替代方式提供原始依赖性。

对于在图书馆,大学,实验室,公司和政府机构中,软件工具可能对其他软件包(或生态系统)以及应充分解决“可用性”的地方,该主题非常重要。

解决这种风险可能意味着从确保不惜一切代价的高可用性到失去一个或多个依赖性的风险的任何事情……应使用风险管理方法来做出影响您项目“安全”的明智选择。

还应注意的是,有些软件包需要二进制可执行文件或二进制库或访问在线API服务,该服务也应该可以让该软件包正常工作,这使风险分析变得复杂并使解决可用性所需的活动变得复杂。

现在以确保依赖关系始终可用...我迅速编制了以下列表。请注意,每个选项都有利弊。您应该根据您的需求评估这些和其他选项:

  1. 将虚拟环境与代码一起存储。创建虚拟环境并在该虚拟环境中安装项目所需的软件包后,您可以将虚拟环境保留为存储库的一部分,例如,以供后代使用。
  2. 主持自己的PYPI实例(或镜像),并保留您依赖于托管的包装的副本: https://packaging.python.org/en/latest/guides/guides/hosting-your-own-own-index/
  3. 使用“ trifact Management工具”,例如来自 https://jfrog.com/artifact-management/ ,您不仅可以主机python packages,还可以主机Docker图像,NMAP软件包和其他类型的文物。
  4. 获取所有依赖项的源代码,并始终从源构建。
  5. 创建一个docker映像,其中项目正常工作并保留图像的备份。
  6. 如果包装需要在线API服务,请考虑替换该服务或通过您可以控制的一个服务。

Short version:

YES, if you want availability... The next big question is how best to keep a backup version of the dependencies? There are some suggestions at the end of this answer.

Long version:

Your question touches on the concept of "Availability" which is one of the three pillars of Information Assurance (or Information Security). The other two pillars are Confidentiality and Integrity... The CIA triad.

PyPI packages are maintained by the owners of those packages, a project that depends on a package and list it as a dependency must take into account the possibility that the owner of the package will pull the package or a version of the package out of PyPI at any moment.

Important Python packages with many dependencies usually are maintained by foundations or organizations that are more responsible with dealing with downstream dependent packages and projects. However keeping support for old packages is very costly and requires extra effort and usually maintainers set a date for end of support, or publish a package lifecycle where they state when a specific version will be removed from the public PyPI server.

Once that happens, the dependents have to update their code (as you did), or provide the original dependency via alternative means.

This topic is very important for procurement in libraries, universities, laboratories, companies, and government agencies where a software tool might have dependencies on other software packages (or ecosystem), and where "availability" should be addressed adequately.

Addressing this risk might mean anything from ensuring high availability at all costs, to living with the risk of losing one or more dependencies... A risk management approach should be used to make informed choices affecting the "security" of your project.

Also it should be noted that, some packages require binary executable or binary libraries or access to a an online API service, which should also be available for the package to work properly, and that complicates the risk analysis and complicates the activities necessary to address availability.

Now to make sure that dependencies are always available... I quickly compiled the following list. Note that each option has pros and cons. You should evaluate these and other options based on your needs:

  1. Store the virtual environment along with the code. Once you create a virtual environment and install the packages you require for the project in that virtual environment, you can keep the virtual environment as part of your repository for example for posterity.
  2. Host your own PyPI instance (or mirror) and keep a copy of packages you depend upon hosted on it: https://packaging.python.org/en/latest/guides/hosting-your-own-index/
  3. Use an "artifact management tool" such as Artifactory from https://jfrog.com/artifact-management/, where you can not only host python packages but also Docker images, nmap packages, and other kinds of artifacts.
  4. Get the source code of all dependencies, and always build from source.
  5. Create a Docker image where the project works properly and keep backups of the image.
  6. If the package requires an online API service, think about replacing that service or mocking it by one you can control.
〃温暖了心ぐ 2025-02-04 14:28:30

鉴于包装文件可在PYPI上可用,您可以使用 pip 下载*。whl 为特定操作系统编译的文件:

pip download --only-binary=:all: package_name

或源分发文件** 。

pip download --no-binary=:all: package_name

或者,如果包装文件在PYPI上不是直接可用的,而是在某些档案中可用的,那么 pyqt4 ,您可以手动下载这些文件。

一旦您拥有软件包文件(*。whl binaries或*。tar.gz ),您应该能够在没有任何Internet连接的情况下安装它们作者:

pip install /path/to/local/package.whl # for *.whl files
pip install /path/to/local/package.tar.gz # for source *.tar.gz files

但是,如果您决定将软件包文件备份到网络存储位置,例如Google Drive,则需要一个Internet连接,因为在这种情况下, pip 需要从URL检索文件然后通过以下方式安装软件包:

pip install https://drive.google.com/drive/home/package_name.tar.gz

Given that the package files are available on PyPI, you can use pip to download the *.whl files compiled for specific OS via:

pip download --only-binary=:all: package_name

or the source distribution files *.tar.gz via:

pip download --no-binary=:all: package_name

Both should download the package files for all the available platforms when you specify :all:.

Alternatively, if the package files are not directly available on PyPI but on some archive as is the case for PyQt4, you can manually download those files.

Once you have the package files (either *.whl binaries or *.tar.gz), you should be able to install them without any internet connection from your local package files by:

pip install /path/to/local/package.whl # for *.whl files
pip install /path/to/local/package.tar.gz # for source *.tar.gz files

However, if you decide to backup your package files to a network storage location e.g. Google drive, you'd need an internet connection, since in this case, pip needs to retrieve the files from the URL and then install the package via:

pip install https://drive.google.com/drive/home/package_name.tar.gz
初见 2025-02-04 14:28:30

我使用 nexus存储库管理器OSS https:///help.sonatype。 com/en/download.html

您可以直接从Docker Image中直接设置PYPI并托管自己的PYPI内部图像。

您将获得本地 pip install 的加速和好处,

您使用全局变量和PIP参数来设置它:
创建并使用Nexus和Nexus

和 Nexus and and and and and and and and and and and and and and and和Nexus可以提供许多其他图像:Docker,Nuget,Gems,Maven等。因此,您可以拥有它。 restapi为一切。

I use Nexus Repository Manager OSS: https://help.sonatype.com/en/download.html

You can proxy pypi and host your own pypi internal images, can be set up directly from a docker image.

And you get the speedup and benefit of local pip install

You use global variables and pip parameters to set it up:
Create and use a PyPi proxy repository on nexus

And Nexus can serve lots of other images: Docker, Nuget, Gems, Maven etc. So you have it one place. Restapi for everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文