在树莓派上安装wxpython(bd7iow---转自国外博客)

寵の児 提交于 2020-08-11 13:02:12

If you need to install wxPython on Raspbian Buster for a project, the installation of that module can be a little bit tricky. It needs to be compiled for Raspbian from source files to have something working nicely.

Here you can find step by step explaination how to do it.

Requirements
Raspberry Pi
Python 3.x
time, lots of time


Step 1
First, you need to open a terminal (shortcut ctrl + alt + t)

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

(libgstreamer-plugins-base0.10-dev这个换到国内源可能安装失败,查过资料是有最新版的可以用)
if you use the pre-installed Python 3:

sudo apt-get install python3.7-dev

Step 2
Now, let’s make the virtual environment. I made mine right off the /home/pi directory, but you can put it anywhere. Some like to put all their 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 -m venv wx

source ~/wx/bin/activate

Step 3
The first thing you need is wxPython.

Go to:

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

Down of the bottom of the choices, you will see “wxPython-4.1.0.tar.gz … Source”.

Download wxPython-4.1.0.tar.gz

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

下载wxpython4.1.0源码

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

cd ~

mv ~Downloads/wxPython-4.1.0.tar.gz

tar xf wxPython-4.1.0.tar.gz

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

cd wxPython-4.1.0

pip3 install -r requirements.txt

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

python3 build.py build bdist_wheel --jobs=2(这里是用多少线程编译,我用3B,=4的话会卡死,用2刚好)

After waiting ~ 8 hours
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.1.0-cp38-cp38-linux_armv7l.whl for Python 3.8(命名看每个人的环境吧)) :

cd ~/wxPython-4.1.0/dist

pip3 install wxPython-4.1.0-cp37-cp37m-linux_armv7l.whl

After waiting ~ 1 hour
Now let’s test it:

cd ~/wxPython-4.1.0.post2/demo

python3 demo.py

Enjoy!

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