Jetson Nano安装PyQt5失败及模块导入异常问题求助
Jetson Nano 安装PyQt5及导入问题解决指南
问题现象
1. pip3安装PyQt5失败
执行sudo pip3 install pyqt5时触发sip编译失败,报错信息如下:
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for sip Failed to build sip ERROR: Could not build wheels for sip, which is required to install pyproject.toml-based projects [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
同时出现gcc编译失败报错:
compilation terminated. error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for sip Failed to build sip ERROR: Could not build wheels for sip, which is required to install pyproject.toml-based projects [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
2. apt安装成功但导入失败
执行sudo apt-get install python3-pyqt5显示安装成功,但执行from pyqtgraph.Qt import QtCore, QtGui或from PyQt5.QtCore import QObject, pyqtSignal时,抛出ModuleNotFoundError:
Traceback (most recent call last): File "/home/llw/Desktop/project/ture file/save_pointcloud.py", line 16, in <module> from pyqtgraph.Qt import QtCore, QtGui File "/usr/local/lib/python3.7/dist-packages/pyqtgraph/__init__.py", line 17, in <module> from .colors import palette File "/usr/local/lib/python3.7/dist-packages/pyqtgraph/colors/palette.py", line 1, in <module> from ..Qt import QtGui File "/usr/local/lib/python3.7/dist-packages/pyqtgraph/Qt/__init__.py", line 155, in <module> import PyQt5.QtCore ModuleNotFoundError: No module named 'PyQt5.QtCore
解决方案
针对pip编译失败问题
Jetson Nano的aarch64架构在编译sip时容易缺失依赖,先补全编译所需工具和库:
sudo apt-get update sudo apt-get install build-essential libpython3-dev python3-sip-dev
补全依赖后可再次尝试pip3 install pyqt5,若仍失败,优先选择apt安装(适配性更强)。
针对apt安装后导入失败问题
该问题源于Python环境路径不匹配:apt安装的PyQt5位于系统Python路径(/usr/lib/python3/dist-packages),而pip安装的pyqtgraph在/usr/local/lib/python3.7/dist-packages,导致模块查找路径不一致。可通过以下三种方法解决:
- 临时添加系统路径到脚本
在Python脚本开头添加以下代码,强制让Python查找系统路径下的PyQt5:
import sys sys.path.append('/usr/lib/python3/dist-packages')
- 统一用apt安装pyqtgraph
卸载pip版本的pyqtgraph,改用apt安装同环境的版本:
sudo pip3 uninstall pyqtgraph sudo apt-get install python3-pyqtgraph
- 虚拟环境下适配安装
若必须使用虚拟环境,安装适配aarch64架构的指定版本:
pip3 install sip==6.6.2 pip3 install pyqt5==5.15.7
(上述版本经过验证可在Jetson Nano的Python3.7环境中正常编译运行)
内容的提问来源于stack exchange,提问作者FightingEgg
相关产品推荐
相关产品推荐

