Install python wheel file without using pip

末鹿安然 提交于 2019-12-17 18:28:07

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/36132350/install-python-wheel-file-without-using-pip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!