是否可以创建一个完全独立的 Python 包? [英] Is it possible to create a fully self-contained Python package?
问题描述
Ansible 是一个 Python 模块,可通过 pip 安装.它依赖于几个依赖项,还有 pip 模块.是否可以将所有这些依赖项和 Ansible 本身汇总"到某种单一的包中,该包可以离线安装,无需 root?安装时最好不需要 pip,尽管它可用于创建包.
Ansible is a python moduel, installable via pip. It relies on several dependencies, also pip modules. Is it possible to "roll up" all of those dependencies and Ansible itself into some sort of a single package, that can be installed offline, without root? It's highly preferable to not need pip for the install, although it will be available for package creation.
我正在尝试在我们的一台服务器上安装 Ansible.服务器无法访问互联网,没有 root 访问权限.未安装 Pip,但安装了 Python.可以在那里安装 pip,但可能很复杂.在服务器上获取任何东西的唯一方法是通过内部 tar.gz 包共享解决方案.
I'm trying to install Ansible on one of our servers. The server does not have access to the internet, there is no root access. Pip is not installed, but Python is. It is possible to get pip installed there, but might be complicated. The only way to get anything on the server is via an internal tar.gz package sharing solution.
我试过摆弄 rpm,保存依赖项,但是没有 root 访问权限结束了这一切.
I've tried fiddling around with rpm, saving dependencies, but the absence of root access put an end to that.
推荐答案
在联网的机器上使用 pip 将所有 deps 下载到本地目录,并带有 --download 和 -r requirements.txt
,然后将该目录放到安装了 pip 的断开连接的机器上,并使用 --no-index 和 --find-links=(archive dir)
进行安装.
Use pip on an internet-connected machine to download all the deps to a local dir with --download and -r requirements.txt
, then drop that dir on the disconnected machine with pip installed, and install using --no-index and --find-links=(archive dir)
.
见https://pip.pypa.io/en/最新/用户指南/#fast-local-installs
这篇关于是否可以创建一个完全独立的 Python 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!