Install python wheel file without using pip

2019-01-23 06:44发布

Is it possible to install a Python wheel without using pip? I always have issues with installing 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.

2条回答
聊天终结者
2楼-- · 2019-01-23 07:17

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.

查看更多
beautiful°
3楼-- · 2019-01-23 07:27

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

Download the pip wheel:

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:

$ 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:

$ 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.

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

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 python executable is pointing at.

查看更多
登录 后发表回答