Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

Install python wheel file without using pip

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"

For users not scripting this but just doing once-off, you may prefer to simply download a pip wheel using your browser. In that case, look for the latest release files here: https://pypi.org/project/pip/#files

Now you have a wheel for pip, and some other wheel file you want to install. You can actually "execute" the pip wheel file to install the 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, even with no pip installation.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...