不使用pip安装python轮文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36132350/
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 17:27:52  来源:igfitidea点击:

Install python wheel file without using pip

pythonpippython-wheel

提问by king

Is it possible to install a Python wheel without using pip? I always have issues with installing with pip, so I usually install libraries manually by copying and pasting. I'm wondering if there is a way to do wheel files in a similar manner.

是否可以在不使用的情况下安装 Python 轮子pip?我总是在安装时遇到问题pip,所以我通常通过复制和粘贴来手动安装库。我想知道是否有办法以类似的方式做轮文件。

采纳答案by king

It is. Actually .whl files are just zip archives, so you can just extract their content and play with libraries path variable to make it work. Yet it is really bad practice.

这是。实际上 .whl 文件只是 zip 档案,因此您可以提取它们的内容并使用库路径变量使其工作。然而,这确实是一种糟糕的做法。

回答by wim

I'm assuming you have internet access, but you don't have a working pip installation.

我假设您可以访问互联网,但您没有有效的 pip 安装

Download the pip wheel:

下载 pip 轮:

wget https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl

To find the url of a release in the first place, you can get the index json endpoint. For example:

要首先找到发布的 url,您可以获取索引 json 端点。例如:

$ curl -s https://pypi.org/pypi/pip/json | jq ".urls[0].url"
"https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl"

"Execute" it with your other wheel file. For example, if you were trying to install setuptools v39.0.1 from bdist, the command would look like this:

用你的其他轮文件“执行”它。例如,如果您尝试从 bdist 安装 setuptools v39.0.1,该命令将如下所示:

$ python pip-10.0.1-py2.py3-none-any.whl/pip install --no-index setuptools-39.0.1-py2.py3-none-any.whl
Processing ./setuptools-39.0.1-py2.py3-none-any.whl
Installing collected packages: setuptools
Successfully installed setuptools-39.0.1

You will now have a working setuptools installation, but no pip.

您现在将有一个有效的 setuptools 安装,但没有 pip。

In case you were wondering, yes you can use the same trick to install pip itself. That command would look like this:

如果您想知道,是的,您可以使用相同的技巧来安装 pip 本身。该命令如下所示:

python pip-10.0.1-py2.py3-none-any.whl/pip install --no-index pip-10.0.1-py2.py3-none-any.whl

And now you should have a working pip installation, associated with whichever interpreter this pythonexecutable is pointing at.

现在你应该有一个工作 pip 安装,与这个python可执行文件指向的任何解释器相关联。