本文介绍了使用 PyQt5 的子模块获取导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Ubuntu 14.04 上安装和使用 PyQt5.在此之前,我一直在使用 Ubuntu 18.04,安装和使用 PyQt5 没有任何问题.由于项目的一些技术需求,我需要用14.04代替.

I am trying to install and use PyQt5 on Ubuntu 14.04. Before this, I had been using Ubuntu 18.04 and I had no problems with the installation and use of PyQt5. Because of some technical needs of a project, I need to use 14.04 instead.

在我第一次启动 Ubuntu 之后,这是我安装东西的顺序:

After I first launch Ubuntu this is the order that I install things:

安装 Python 3.6:

Install Python 3.6:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6

安装QT5

sudo apt-get install build-essential
sudo apt-get install qtcreator
sudo apt-get install qt5-default

安装 PyQt5

sudo apt-get install python3-pyqt5
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools

这完成后,我运行这个测试代码,看看是否出现导入错误:

After this is completed, I run this test code to see if I get an import error:

import sys
from PyQt5 import QtCore, QtWidgets

当我运行它时,出现此错误.它给出了 PyQt5 的任何子模块的错误.在 Ubuntu 18.04 上,我对 qt5 和 pyqt5 执行了与上面相同的安装步骤,并且运行良好.(没有安装python 3.6,因为它已经安装了Ubuntu 18).

When I run it, I get this error. It gives an error for any sub module of PyQt5. On Ubuntu 18.04, I followed the same installation steps as above for qt5 and pyqt5 and it worked perfectly. (Did not install python 3.6 because it is already installed with Ubuntu 18).

回溯(最近一次调用最后一次):
文件/home/ms/test.py",第 2 行,
从 PyQt5 导入 QtCore
导入错误:无法导入名称QtCore"

我也尝试过使用 pip 或 pip3 安装 pyqt5,但出现错误.

I have also tried installing pyqt5 with pip or pip3, but I get an error.

pip3 install pyqt5

错误:

Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_ms/pyqt5
Storing debug log for failure in /home/ms/.pip/pip.log

任何帮助将不胜感激.过去几天我一直在努力解决这个问题,但仍然不知道可能是什么问题.

Any help would be greatly appreciated. I have been working on trying to fix this for the past couple days with still no idea what the problem could be.

推荐答案

以下步骤用于在 ubuntu: 14.04 的 docker 中安装 PyQt5:

The following steps use to install PyQt5 in a docker with ubuntu: 14.04:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
sudo apt-get install curl
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.6 get-pip.py
sudo python3.6 -m pip install --upgrade pip
sudo python3.6 -m pip install pyqt5==5.9.2
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev libfontconfig1
python3.6 -c "from PyQt5 import QtCore, QtWidgets"

这篇关于使用 PyQt5 的子模块获取导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:45
查看更多