Python's first mainstream packaging format was the .egg file, and now there is a new member called Wheel (*.whl) in the big family. wheel "is designed to contain all files for PEP 376 compatible installation (a format very close to the on-disk format)". In this article, we will learn how to create a wheel and how to install a wheel in a virtualenv.
Get started
You need pip to create a wheel. To learn to install pip, I strongly recommend reading the pip installation page
. If you have already installed pip, then you need to upgrade it to the latest version. You only need to do this: In a console window, enter the following command:
pip install --upgrade pip
After completing the above work, we are ready to learn to create a wheel!
Create wheel
First, you need to install the wheel package:
pip install wheel
In the next step, we will use the unidecode package to create our first wheel, because when I am writing this article, our wheel package has not been created yet, and I will use this package in multiple projects next.
pip wheel --wheel-dir=my_wheels Unidecode
Now, you have a wheel named Unidecode-0.04.14-py26-none-any.whl in the my_wheels folder, let's learn to install the newly created wheel!
Install Python
wheel
Let's create a virtualenv
For testing, you can read more about virtualenv here. Once you have installed virtualenv, use the following command to test:
virtualenv test
This will create a testable virtual sandbox for us with pip. Before proceeding to the next step, make sure to run activate in the s folder to enable virtualenv. Now virtualenv does not include wheel, so you need to install wheel again:
pip install wheel
Once the wheel is installed, we use the following command to install the wheel we created earlier:
pip install --use-wheel --no-index --find-links=path/to/my_wheels Unidecode
In order to test whether it is running properly, run Python from the s folder of your virtualenv and try to import unidecode. If it is imported normally, then you have successfully installed the wheel you created before!
Note: I installed a troublesome old version of virtualenv when I started. Make sure you upgraded to the latest version, or you spent a lot of time tossing to make it work.
*. The whl files are similar to *.egg files: in fact they are all "disguised" *.zip files. If you change the *.whl file name extension to *.zip, you can open it with your zip application and view the files and folders it contains.
to sum up
Now you are ready to create your own wheel, which is like a great way to create a local warehouse for your own quick installation projects. You can create multiple different wheel warehouses, which is the same as switching between different test versions. When combined with virtualenv, you will have a very convenient method through which you can see how the new version's dependencies can affect your project without downloading them multiple times.
Knowledge point expansion:
Python wheel package file name format
0.12.4 – Package version
cp36-python implementation and version, cp:CPython. ip:IronPython, jy:Jython, orpp: PyPy, version: 3.6.
cp36m -abi tag
win_amd64-system platform tag
So far, this article on the usage of wheel in python is introduced. For more related python wheel, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you will support ZaLou.Cn more in the future. !
Recommended Posts