36

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.

2 Answers 2

70

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/50/c2/e06851e8cc28dcad7c155f4753da8833ac06a5c704c109313b8d5a62968a/pip-23.2.1-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/50/c2/e06851e8cc28dcad7c155f4753da8833ac06a5c704c109313b8d5a62968a/pip-23.2.1-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 v68.0.0 from a wheel file without internet access, the command would look like this:

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

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-23.2.1-py3-none-any.whl/pip install --no-index pip-23.2.1-py3-none-any.whl 

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

Sign up to request clarification or add additional context in comments.

10 Comments

Download the pip wheel you say! But how to find it? And what about the second wheel - for setuptools? They exist, I know - that is what cpython includes in ensurepip. But finding them? Not so easy imho. No down vote (might not even be able to considering my status here ;) - but imho - only half an answer.
@MichaelFelt OK, I've added the instruction for how to automate finding the download url from index.
muchas gracias! What I was looking for! - except, seems I also need a new command (jq). Anyway, I can dig. Thx!
The trick with executing the command from the wheel file is just awesome.
@wim I get this error: C:\Users\user1\AppData\Local\Programs\Python\Python310\python.exe: can't find 'main' module in 'C:\\Users\\user1\\Downloads\\pip-10.0.1-py2.py3-none-any.whl\\pip'
|
21

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.

8 Comments

play with libraries path variable to make it work ?? Can you give the cmd line of code to execute ?
@Code_10 check this article leemendelowitz.github.io/blog/…
If you don't know where you should unzip it, you can look at the python path like this: import sys; print(sys.path)
"Yet it is really bad practice." Can you elaborate?
Regarding what a "proper" installation does (packaging standards have changed since 2016, but the current information on this specific topic was probably roughly true then as well), see the PyPA guide to the wheel format.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.