I have been tinkering with GoLang for a while and haven’t been using Python until today I came across a very interesting Python framework called kivy (“Kee-vee”?) It’s a very nice frame work that runs OpenGL with accelerated hardware to give you a smooth graphical user interface. It also allows multi-touch for inputs. It claims to be able to deploy on any platform including Android. That’s very cool!.
However, I ran into trouble quickly when I realize that I need Cython and other packages to use kivy. My development environment is in Windows (I know I should use Linux, but we use Windows at work so I want to stay compatible with work). Normally this is not a problem since I can go to my favorite Windows Binaries for Python Extension Packages webpage maintained by Mr. Christopher Gohlke. He pretty much has everything you can think of for Windows binary packages. It’s a lot cumbersome for me to go hunt down the Python sources for these packages and try to do the Python install myself. It’s so much easier to go to a one stop shop like Mr. Gohlke’s page and just install the packages I want. The trouble is the page is now using Wheel files instead of the EXE files for the packages. This requires using PIP to do the installation and I have no idea at first how to do that. Well, let me share with you what I found so that you can save time and frustration that require to use this amazing page of Python packages.
I’ll make the instruction as a brand new Python install. I chose Python 2.7.13 (32-bit) since it’s the latest 2.7.x as of the time of this writing. I didn’t pick Python 3.x because we use Python 2.7.x at work and again I want to be compatible with work. Someday I’ll try Python 3.x but so far many libraries are in Python 2.7.x and not everything has migrated over to Python 3.x yet even though it’s been almost like a decade since Python 3.x came out (2008 I think). This instruction should technically work for any versions but you just need to make sure you match the packages with the version you are using. For me, it’ll be 2.7.x and 32-bit for all the packages.
Now you need to make sure you have Python in you windows path variable or you can’t call python.exe from anywhere in the command line. Click Start Menu and type into the search box “Edit the system environment variables”. Click on the option that showed up in search under Control Panel result.
Now click on the “Environment Variables …” button under the System Properties screen that showed up.
Click on the Path variable under System variables. You might have to scroll down if you have a lot of stuff in your System variables like I do. Then click “Edit …”
For Windows 10 (with Anniversary update), Microsoft kindly added a new easier to read screen for the path variable management. If you have a different version of Windows, you’ll have to look through the long line of paths separated by semicolons (;). To add path, just add a semicolon to the last path in the line and then type in the new path you want. For Windows 10, just click on “New” button to add path variables. Add the following paths (defaulted by Python 2.7.x install. If you install python in a different folder, you’ll have to use your custom path):
Now that the difficult part is done, time to move on to PIP install.
Download and Install PIP
This page shows you how to install PIP but I’ll explain how I did it. Basically, right click on get-pip.py and save it to some folder. I put it in a C:\python_packages\ where I collect my packages to install.
Launch a command prompt (Click start button, type “CMD” into the search box and hit enter.). Get to the directory where you keep the get-pip.py then type:
If you correctly setup your path variables as I explained in the previous section then this should execute a pip package download. Once this is done, you are almost ready to be able to use the Python wheel packages.
Install Wheel Requirements to Use Mr. Gohlke’s packages
Scroll down and look for Pip package then download pip-9.01-py2.py3-none-any.whl from Gohlke page into any folder. I recommend using the same folder where you put the get-pip.py script.
[Update 4/21/2017]: You can get PIP wheel from Python Package Index as well. It’s a bit faster to download than Gohlke page. Download the
If your command prompt is still there and you are still in the same folder, you can type the following command:
pip install python.exe pip-9.0.1-py2.py3-none-any.whl/pip install pip-9.0.1-py2.py3-none-any.whl
It should say something about the requirement is installed. If it doesn’t come up with error then you are good to go.
Since we have PIP installed and requirements met, we can try installing a package from Mr. Gohlke’s page. Let’s try installing Cython since we’ll need that for Kyvi. Look for Cython-0.25.2-cp27-cp27m-win32.whl or whatever the latest version would be for Python 2.7.x and 32-bit. Click on the link and you’ll be prompted for a save file location. Again, I’ll put the package into the same folder we have been working with. Kudos to Mr. Gohlke, The page is pretty well organized and kept up-to-date. You can see from the file name what Python version and Windows version you need.
Launch a command prompt again and navigate to our C:\python_packages folder. Type the following command to install the Cython package:
pip install pip install Cython-0.25.2-cp27-cp27m-win32.whl
You should see this message if everything went well:
If you get an error saying that pip is unrecognized then you need to make sure that you have the path C:\Python27\Scripts in your path variables. Also make sure to close your command prompt and relaunch it any time you updated your path variables. The command prompt doesn’t know about the new variables until you restart it.
The generic command for installing any packages is just:
pip install SomePackage.whl
That’s it for installing Windows Binary wheels!
Let’s finish installing Kyvi now that we have Cython installed.
First make sure that we have the latest pip wheel and setup tools using the following command:
python -m pip install --upgrade pip wheel setuptools
Install all the dependencies required to run Kyvi:
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
python -m pip install kivy.deps.gstreamer
You could use a command line, but I kept running into a memory error issue maybe due to it being a large file (121 MB) and my firewall and anti-virus program so I just went to the PyPI site to download the wheel. I downloaded the appropriate version for my Python 2.7, 32-bit. ( kivy.deps.gstreamer-0.1.12-cp27-cp27m-win32.whl). Once the file is downloaded to our usual location, run pip install:
pip install kivy.deps.gstreamer-0.1.12-cp27-cp27m-win32.whl
There shouldn’t be any error messages if everything went well. Finally, install kivy itself:
python -m pip install kivy
Now let’s run an example python script using kivy to make sure that we have successfully installed kivy. In command prompt, type in this command:
If everything was installed correctly, you’ll see a brief script execution in the command prompt and you’ll be greeted with the hello world demo:
Now it’s time to have fun using kivy for your GUI. I find it to be much prettier than Tk and much easier to use than Qt. There are a lot of resources from kivy.org. Here’s the link to building your first example app in kivy.