Build wxPython On Raspberry Pi

Instructions by James Key

These are the build and install instructions.


Updated to wxPython 4.0.7.post2 and GTK3!

NEW NOTE!!! It seems I was able to get GTK3 working. The short story is you need to add libghc-gtk3-dev to one of the sudo apt get install ... statements. I also added libwxgtk3.0-gtk3-dev during my experiments so it may be quired also.

    $ sudo apt-get update

    $ sudo apt-get install dpkg-dev build-essential libjpeg-dev libtiff-dev libsdl1.2-dev libgstreamer-plugins-base0.10-dev libnotify-dev freeglut3 freeglut3-dev libwebkitgtk-dev libghc-gtk3-dev libwxgtk3.0-gtk3-dev

This is working for Python 3.8.2 on Raspbian Buster and wxPython 4.0.7.post2 on a Pi 4. I haven't tried it on my pi 3 or my pi zero yet but I don't expect any issues other than the pi zero's small size and processor. Note: I have been able to follow this process for all wxPython releases and Python 3.x releases.


This does not seem to work with GTK3 at the moment. So we will stick with GTK2.

READ THEM ALL FIRST!

Especially the note at the end.

The first part of this is optional. I have tested this on the Python 3.x versions that come default with Raspbian. To use Python 3.8.x or another specific version you will need to install it first, which means building it.

If you wish, update the version numbers to the latest release. I know that this version works, and it's the most recent as of the writing of these directions.

These instructions are based on the Github gist:

https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f

Optional:


First, we need to set up the build dependencies.

    $ sudo apt-get update

    $ sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev

Then download and build Python.

    $ wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz

    $ tar xf Python-3.8.2.tar.xz

    $ cd Python-3.8.2

    $ ./configure –-enable-optimizations

    $ make

    $ sudo make altinstall

Build and Install:


Okay so you want or need wxPython 4.0.x on your Raspberry Pi or you like to watch lots of messages scroll by on long builds. Either way, this is how to do it.

First things first MAKE A VIRTUAL ENVIRONMENT for the build and install. Okay this isn't strictly needed but if you don't know about venv or virtual environments, they do keep the environment cleaner for each project. The only issue is that you need to run the pip install for each virtual environment you want to use it in. It's your choice.

These instructions will use Python 3.7 but they are identical for 3.8, just substitute the version number you want. For example:

    $ python3.7 ...

would be

    $ python3.8 ...

Not too scary, right?

These instructions are based on the Github Phoenix README:

https://github.com/wxWidgets/Phoenix/blob/master/README.rst

Okay now to make the virtual environment. I made mine right off the /home/pi directory but you can put it anywhere. Some like to put all there virtual environments (virtenv) in specific locations.

Let's make one (wx is the name of the virtenv we are creating, change it to suit):

    $ cd ~

    $ python3.8 -m venv wx

    $ source ~/wx/bin/activate

The last line activates the environment. Your prompt should change to show that you are in an active virtenv. To deactivate type deactivate. If you log out, close the terminal, or restart the Pi, or open a new terminal, you need to run the activate command again. If not you won't be in the virtual environment.

The first thing you need is wxPython. Go to:

https://pypi.org/project/wxPython/

PLEASE use the tarball from these links, I too wanted the latest, greatest version. Don't. If you download it from github you need to do a massive amount of work. Let the marvelous people who developed this package do that, then thank them.

Down at the bottom of the choices you'll see “wxPython-4.0.7.post2.tar.gz … Source”.

Download wxPython-4.0.7.post2.tar.gz

Use your browser if you can. The file should go into your ~/Downloads folder. The link currently is the very human unfriendly:

https://files.pythonhosted.org/packages/b9/8b/31267dd6d026a082faed35ec8d97522c0236f2e083bf15aff64d982215e1/wxPython-4.0.7.post2.tar.gz

Ick. Okay, that's not exactly a professional comment but sometimes you just have to call it what it is.

    $ cd ~

    $ mv ~/Downloads/wxPython-4.0.7.post2.tar.gz .

    $ tar xf wxPython-4.0.7.post2.tar.gz

Okay, here we go. Let's make sure we have the dependencies.

    $ sudo apt-get update

    $ sudo apt-get install dpkg-dev build-essential libjpeg-dev libtiff-dev libsdl1.2-dev libgstreamer-plugins-base0.10-dev libnotify-dev freeglut3 freeglut3-dev libwebkitgtk-dev libghc-gtk3-dev libwxgtk3.0-gtk3-dev

If you are using a custom Python that you built above you are all set to continue but if you are using the pre-installed Python 3:

    $ sudo apt-get install python3.7-dev

or for whatever Python3.x is install in your Raspbian ie. python3.6-dev

Next step, make sure you are in the environment you want to install wxPython into.

    $ cd wxPython-4.0.7.post2
    $ pip3 install -r requirements.txt

Okay, the next part is the big one. This will take a while, anywhere from a few hours, to 18+ hours on a Pi zero.

    $ python3 build.py build bdist_wheel

Optionally, if you need GTK2 instead of GTK3 use the --gtk2 flag. If you are on a Pi Zero the --jobs=1 flag seems to help hangups and is limits the compile processes to 1 at a time.

    $ python3 build.py build bdist_wheel --jobs=1 --gtk2

Now to install it in Python as a package (the name of this file varies depending on the Python version you build it with. ie. wxPython-4.0.7.post2-cp38-cp38-linux_armv7l.whl for Python 3.8) :

    $ cd ~/wxPython-4.0.7.post2/dist

    $ pip3 install wxPython-4.0.7.post2-cp37-cp37m-linux_armv7l.whl

Now let’s test it:

    $ cd ~/wxPython-4.0.7.post2/demo

    $ python3 demo.py

Notes:

The build.py script has many options, but I will warn you unless you know what your doing, don't play with them. I had built the package for ver 3.4 then decided to try 3.6. So I ran the 'cleanall' option to clean out the last builds binaries. It did and it cleaned all the SIP and Doxygen bits out too. That defeated the whole point of me getting the pypi tarball. To clean up, delete the directory and extract it again.

Beware you may need an SD card larger than 16MBs

**Other things to note** There were a few times that my pi seemed to freeze. Leave it alone for a while. Give it 15-20 minutes. If it doesn't recover unplug it, enable the virtenv and restart by using your last command. Usually, the 'pip install'. Above all don't panic.

BuildWxPythonOnRaspberryPi (last edited 2020-03-13 17:46:47 by JamesKey)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.