在没有互联网的情况下安装 python 包并使用源代码作为 .tar.gz 和 .whl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36725843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:16:30  来源:igfitidea点击:

installing python packages without internet and using source code as .tar.gz and .whl

pythonpipopenstack

提问by srinath

we are trying to install couple of python packages without internet.

我们正在尝试在没有互联网的情况下安装几个 python 包。

For ex : python-keystoneclient

For that we have the packages downloaded from https://pypi.python.org/pypi/python-keystoneclient/1.7.1and kept it in server.

为此,我们从https://pypi.python.org/pypi/python-keystoneclient/1.7.1下载了软件包并将其保存在服务器中。

However, while installing tar.gz and .whl packages , the installation is looking for dependent packages to be installed first. Since there is no internet connection in the server, it is getting failed.

但是,在安装 tar.gz 和 .whl 包时,安装会先寻找要安装的依赖包。由于服务器中没有互联网连接,所以它正在失败。

For ex : For python-keystoneclient we have the following dependent packages

例如:对于python-keystoneclient,我们有以下依赖包

stevedore (>=1.5.0)
six (>=1.9.0)
requests (>=2.5.2)
PrettyTable (<0.8,>=0.7)
oslo.utils (>=2.0.0)
oslo.serialization (>=1.4.0)
oslo.i18n (>=1.5.0)
oslo.config (>=2.3.0)
netaddr (!=0.7.16,>=0.7.12)
debtcollector (>=0.3.0)
iso8601 (>=0.1.9)
Babel (>=1.3)
argparse
pbr (<2.0,>=1.6)

When i try to install packages one by one from the above list, once again its looking for nested dependency .

当我尝试从上面的列表中一个一个安装软件包时,它再次寻找嵌套依赖项。

Is there any way we could list ALLthe dependent packages for installing a python module like python-keystoneclient.

有什么办法可以列出所有用于安装像 python-keystoneclient 这样的 python 模块的依赖包。

回答by Praveen Yalagandula

This is how I handle this case:

我是这样处理这个案子的:

On the machine where I have access to Internet:

在我可以访问 Internet 的机器上:

mkdir keystone-deps
pip download python-keystoneclient -d "/home/aviuser/keystone-deps"
tar cvfz keystone-deps.tgz keystone-deps

Then move the tar file to the destination machine that does not have Internet access and perform the following:

然后将 tar 文件移动到无法访问 Internet 的目标计算机并执行以下操作:

tar xvfz keystone-deps.tgz
cd keystone-deps
pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index

You may need to add --no-deps to the command as follows:

您可能需要将 --no-deps 添加到命令中,如下所示:

pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index --no-deps

回答by rouble

If you want to install a bunch of dependencies from, say a requirements.txt, you would do:

如果你想安装一堆依赖,比如一个requirements.txt,你可以这样做:

mkdir dependencies
pip download -r requirements.txt -d "./dependencies"
tar cvfz dependencies.tar.gz dependencies

And, once you transfer the dependencies.tar.gz to the machine which does not have internet you would do:

而且,一旦您将dependencies.tar.gz 转移到没有互联网的机器上,您将执行以下操作:

tar zxvf dependencies.tar.gz
cd dependencies
pip install * -f ./ --no-index

回答by Burhan Khalid

We have a similar situation at work, where the production machines have no access to the Internet; therefore everything has to be managed offline and off-host.

我们在工作中也有类似的情况,生产机器无法上网;因此,一切都必须离线和脱离主机进行管理。

Here is what I tried with varied amounts of success:

这是我尝试的各种成功方法:

  1. basketwhich is a small utility that you run on your internet-connected host. Instead of trying to install a package, it will instead download it, and everything else it requires to be installed into a directory. You then move this directory onto your target machine. Pros: very easy and simple to use, no server headaches; no ports to configure. Cons: there aren't any real showstoppers, but the biggest one is that it doesn't respect any version pinning you may have; it will always download the latest version of a package.

  2. Run a local pypi server. Used pypiserverand devpi. pypiserveris super simple to install and setup; devpitakes a bit more finagling. They both do the same thing - act as a proxy/cache for the real pypi and as a local pypi server for any home-grown packages. localshopis a new one that wasn't around when I was looking, it also has the same idea. So how it works is your internet-restricted machine will connect to these servers, they are then connected to the Internet so that they can cache and proxy the actual repository.

  1. basket这是您在连接 Internet 的主机上运行的一个小实用程序。它不会尝试安装软件包,而是下载它,并将它需要的所有其他内容安装到目录中。然后将该目录移动到目标机器上。优点:非常容易使用,没有服务器头疼;没有要配置的端口。缺点:没有任何真正的亮点,但最大的是它不尊重您可能拥有的任何版本固定;它将始终下载最新版本的软件包。

  2. 运行本地 pypi 服务器。使用pypiserverdevpipypiserver安装和设置超级简单;devpi需要更多的折腾。它们都做同样的事情——充当真正的 pypi 的代理/缓存,并充当任何本土包的本地 pypi 服务器。localshop是一个新的,在我看的时候并不存在,它也有同样的想法。因此,它的工作原理是您的受 Internet 限制的机器将连接到这些服务器,然后将它们连接到 Internet,以便它们可以缓存和代理实际存储库。

The problem with the second approach is that although you get maximum compatibility and access to the entire repository of Python packages, you still need to make sure any/all dependencies are installed on your target machines (for example, any headers for database drivers and a build toolchain). Further, these solutions do not cater for non-pypi repositories (for example, packages that are hosted on github).

第二种方法的问题在于,尽管您获得了最大的兼容性和对整个 Python 包存储库的访问权限,但您仍然需要确保在目标机器上安装了任何/所有依赖项(例如,数据库驱动程序的任何标头和构建工具链)。此外,这些解决方案不适合非 pypi 存储库(例如,托管在 github 上的包)。

We got very far with the second option though, so I would definitely recommend it.

不过,我们对第二个选项走得很远,所以我肯定会推荐它。

Eventually, getting tired of having to deal with compatibility issues and libraries, we migrated the entire circus of servers to commercially supported docker containers.

最终,厌倦了处理兼容性问题和库,我们将整个服务器迁移到商业支持的 docker 容器。

This means that we ship everything pre-configured, nothing actually needs to be installed on the production machines and it has been the most headache-free solution for us.

这意味着我们运送所有预先配置的东西,实际上不需要在生产机器上安装任何东西,这对我们来说是最令人头疼的解决方案。

We replaced the pypi repositories with a local docker image server.

我们用本地 docker 图像服务器替换了 pypi 存储库。

回答by moveax3

pipdeptreeis a command line utility for displaying the python packages installed in an virtualenv in form of a dependency tree. Just use it: https://github.com/naiquevin/pipdeptree

pipdeptree是一个命令行实用程序,用于以依赖树的形式显示安装在 virtualenv 中的 python 包。只需使用它:https: //github.com/naiquevin/pipdeptree

回答by user2532244

This isn't an answer. I was struggling but then realized that my install was trying to connect to internet to download dependencies.

这不是答案。我很挣扎,但后来意识到我的安装试图连接到互联网以下载依赖项。

So, I downloaded and installed dependencies first and then installed with below command. It worked

因此,我首先下载并安装了依赖项,然后使用以下命令进行安装。有效

python -m pip install filename.tar.gz