当前位置: 首页 > 工具软件 > thinker > 使用案例 >

在Thinker board开发板上安装PyQt5

从阎宝
2023-12-01

板子是Thinkerboard 2s 内存2gb 由于内存过小的原因 因此“只能用手动编译的方法去安装”

安装参考的下面这篇文章

嵌入式ARM 64位平台源码编译安装PyQt5及其在虚拟环境中的调用配置

踩过的坑:

1、找不到sip
2、SystemError: initialization of QtWidgets failed without raising an exception

安装步骤

1、安装的虚拟环境为miniconda

2、下载 sip-4.19.25 pyqt5-5.15.2
注意必须是这两个版本否则不保证能运行

3、在miniconda中创建虚拟环境pyqt5

conda create -n pyqt5 python=3.7

4、切换到虚拟环境

conda activate pyqt5

5、安装qmake

sudo apt install qt5-default

验证qmake是否安装好

qmake --version

6、安装编译需要的SIP包

sudo apt-get install cmake gcc g++
pip3 install --upgrade pip
pip3 install wheel setuptools

编译包参考

编译包参考的教程

7、编译SIP包

(pyqt5) user@admin:~$ cd ./pyqt5/
(pyqt5) user@admin:~$ tar zxvf sip-4.19.25.tar.gz
pyqt5) user@admin:~/pyqt5$ cd ./sip-4.19.25
(pyqt5) user@admin:~/pyqt5/sip-4.19.25$ sudo python3 configure.py --sip-module PyQt5.sip
This is SIP 4.19.25 for Python 3.9.2 on linux.
The SIP code generator will be installed in /usr/bin.
The sip.h header file will be installed in /usr/include/python3.7m.
The PyQt5.sip module will be installed in /usr/lib/python3/dist-packages/PyQt5.
The sip.pyi stub file will be installed in
/usr/lib/python3/dist-packages/PyQt5.
The default directory to install .sip files in is /usr/share/sip.
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
(pyqt5) user@admin:~/pyqt5/sip-4.19.25$ sudo make
...
(pyqt5) user@admin:~/pyqt5/sip-4.19.25$ sudo make install
make[1]: 进入目录“/home/user/pyqt5/sip-4.19.25/sipgen”
cp -f sip /usr/bin/sip
cp -f /home/user/pyqt5/sip-4.19.25/siplib/sip.h /usr/include/python3.7m/sip.h
make[1]: 离开目录“/home/user/pyqt5/sip-4.19.25/sipgen”
make[1]: 进入目录“/home/user/pyqt5/sip-4.19.25/siplib”
cp -f sip.so /usr/lib/python3/dist-packages/PyQt5/sip.so
strip /usr/lib/python3/dist-packages/PyQt5/sip.so
cp -f /home/user/pyqt5/sip-4.19.25/sip.pyi /usr/lib/python3/dist-packages/PyQt5/sip.pyi
make[1]: 离开目录“/home/user/pyqt5/sip-4.19.25/siplib”
cp -f sipconfig.py /usr/lib/python3/dist-packages/sipconfig.py
cp -f /home/user/pyqt5/sip-4.19.25/sipdistutils.py /usr/lib/python3/dist-packages/sipdistutils.py
/usr/bin/python3 /home/user/pyqt5/sip-4.19.25/mk_distinfo.py "" /usr/lib/python3/dist-packages/PyQt5_sip-4.19.25.dist-info installed.txt
 

8、源码编译安装pyqt5包

(pyqt5) user@admin:~$ cd ./pyqt5/
(pyqt5) user@admin:~$ tar zxvf PyQt5-5.15.2.tar.gz
(pyqt5) user@admin:~/pyqt5$ cd ./PyQt5-5.15.2
(pyqt5) user@admin:~/pyqt5/PyQt5-5.15.2$ sudo python3 configure.py
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
This is the GPL version of PyQt 5.15.2 (licensed under the GNU General Public
License) for Python 3.9.2 on linux.
 
Type 'L' to view the license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.
 
Do you accept the terms of the license? yes
...
(pyqt5) user@admin:~/pyqt5/PyQt5-5.15.2$ sudo make -j4
...
g++ -Wl,--version-script=pyrcc.exp -Wl,-O1 -shared -o libpyrcc.so sippyrccRCCResourceLibrary.o sippyrcccmodule.o rcc.o  -lQt5Xml -lQt5Core -lpthread  
cp -f libpyrcc.so pyrcc.so
make[1]: 离开目录“/home/user/pyqt5/PyQt5-5.15.2/pyrcc”
cd Qt/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/user/pyqt5/PyQt5-5.15.2/Qt/Qt.pro ) && make -f Makefile 
make[1]: 进入目录“/home/user/pyqt5/PyQt5-5.15.2/Qt”
gcc -c -pipe -O2 -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DSIP_PROTECTED_IS_PUBLIC -Dprotected=public -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -I. -I. -isystem /usr/include/python3.7m -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o sipQtcmodule.o sipQtcmodule.c
rm -f libQt.so
g++ -Wl,--version-script=Qt.exp -Wl,-O1 -shared -o libQt.so sipQtcmodule.o  -lpthread  
cp -f libQt.so Qt.so
make[1]: 离开目录“/home/user/pyqt5/PyQt5-5.15.2/Qt”
(pyqt5) user@admin:~/pyqt5/PyQt5-5.15.2$ sudo make install 
...
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtPrintSupport.pyi /usr/lib/python3/dist-packages/PyQt5/QtPrintSupport.pyi
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtSql.pyi /usr/lib/python3/dist-packages/PyQt5/QtSql.pyi
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtTest.pyi /usr/lib/python3/dist-packages/PyQt5/QtTest.pyi
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtWidgets.pyi /usr/lib/python3/dist-packages/PyQt5/QtWidgets.pyi
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtXml.pyi /usr/lib/python3/dist-packages/PyQt5/QtXml.pyi
/usr/lib/qt5/bin/qmake -install qinstall /home/user/pyqt5/PyQt5-5.15.2/QtDBus.pyi /usr/lib/python3/dist-packages/PyQt5/QtDBus.pyi
/usr/bin/python3 /home/user/pyqt5/PyQt5-5.15.2/mk_distinfo.py "" /usr/lib/python3/dist-packages/PyQt5-5.15.2.dist-info installed.txt
...
 

9、虚拟环境中调用pyqt的配置

(pyqt5) user@admi:~/pyqt5/PyQt5-5.15.2$ cd /usr/lib/python3/dist-packages/
(pyqt5) user@admin:/usr/lib/python3/dist-packages$ sudo tar zcvf pyqt5.tar.gz ./PyQt5/
./PyQt5/
./PyQt5/pyrcc.so
./PyQt5/QtDBus.pyi
./PyQt5/QtSql.so
./PyQt5/pyrcc_main.py
./PyQt5/QtSql.pyi
./PyQt5/QtNetwork.pyi
./PyQt5/QtNetwork.so
./PyQt5/sip.so
./PyQt5/QtGui.so
./PyQt5/_QOpenGLFunctions_4_1_Core.so
./PyQt5/QtDBus.so
./PyQt5/QtWidgets.pyi
./PyQt5/QtTest.so
./PyQt5/QtOpenGL.so
./PyQt5/QtOpenGL.pyi
./PyQt5/pylupdate.so
./PyQt5/_QOpenGLFunctions_2_1.so
./PyQt5/uic/
./PyQt5/uic/properties.py
./PyQt5/uic/exceptions.py
./PyQt5/uic/Loader/
./PyQt5/uic/Loader/loader.py
./PyQt5/uic/Loader/qobjectcreator.py
./PyQt5/uic/Loader/__init__.py
./PyQt5/uic/pyuic.py
./PyQt5/uic/Compiler/
./PyQt5/uic/Compiler/misc.py
./PyQt5/uic/Compiler/qtproxies.py
./PyQt5/uic/Compiler/qobjectcreator.py
./PyQt5/uic/Compiler/indenter.py
./PyQt5/uic/Compiler/proxy_metaclass.py
./PyQt5/uic/Compiler/__init__.py
./PyQt5/uic/Compiler/compiler.py
./PyQt5/uic/port_v2/
./PyQt5/uic/port_v2/proxy_base.py
./PyQt5/uic/port_v2/string_io.py
./PyQt5/uic/port_v2/as_string.py
./PyQt5/uic/port_v2/__init__.py
./PyQt5/uic/port_v2/ascii_upper.py
./PyQt5/uic/driver.py
./PyQt5/uic/icon_cache.py
./PyQt5/uic/__init__.py
./PyQt5/uic/widget-plugins/
./PyQt5/uic/widget-plugins/qtcharts.py
./PyQt5/uic/widget-plugins/qaxcontainer.py
./PyQt5/uic/widget-plugins/qtwebkit.py
./PyQt5/uic/widget-plugins/qtquickwidgets.py
./PyQt5/uic/widget-plugins/qtwebenginewidgets.py
./PyQt5/uic/widget-plugins/qtprintsupport.py
./PyQt5/uic/widget-plugins/qscintilla.py
./PyQt5/uic/port_v3/
./PyQt5/uic/port_v3/proxy_base.py
./PyQt5/uic/port_v3/string_io.py
./PyQt5/uic/port_v3/as_string.py
./PyQt5/uic/port_v3/__init__.py
./PyQt5/uic/port_v3/ascii_upper.py
./PyQt5/uic/uiparser.py
./PyQt5/uic/objcreator.py
./PyQt5/_QOpenGLFunctions_2_0.so
./PyQt5/QtPrintSupport.so
./PyQt5/QtXml.so
./PyQt5/__init__.py
./PyQt5/sip.pyi
./PyQt5/pylupdate_main.py
./PyQt5/QtGui.pyi
./PyQt5/QtXml.pyi
./PyQt5/QtWidgets.so
./PyQt5/QtCore.pyi
./PyQt5/QtPrintSupport.pyi
./PyQt5/QtTest.pyi
./PyQt5/Qt.so
./PyQt5/QtCore.so
(pyqt5) user@admin:/usr/lib/python3/dist-packages$ sudo cp ./pyqt5.tar.gz /home/user/pyqt5/lib/python3.7/site-packages/
(pyqt5) user@admin:~$ cd /home/user/pyqt5/lib/python3.7/site-packages/
(pyqt5) user@admin:~/pyqt5/lib/python3.7/site-packages$ tar zxvf pyqt5.tar.gz
...

10、安装完成之后 还回到 /usr/lib/python3 文件下 将sip开头的所有文件全部复制到你的虚拟环境中site-packages文件夹中

参考资料

树莓派配置环境细节(JDK+pycharm+miniconda+pyqt5+opencv-python)

嵌入式ARM 64位平台源码编译安装PyQt5及其在虚拟环境中的调用配置

 类似资料: