简体   繁体   English

Python import error cannot import name QtGui in PyQt5 Ubuntu 16

[英]Python Import error cannot import name QtGui in PyQt5 Ubuntu 16

I am working on a pyqt5 project in Ubuntu16.04 .我正在 Ubuntu16.04 中的pyqt5项目上Ubuntu16.04 To install pyqt5 , I used the command sudo apt-get install python3-pyqt5 .为了安装pyqt5 ,我使用了命令sudo apt-get install python3-pyqt5 In Ubuntu16.04 , python3.5 comes preinstalled so initially I designed everything with python3.5 .Ubuntu16.04中, python3.5是预装的,所以最初我用python3.5设计了所有东西。 Application was running fine.应用程序运行良好。

Later I upgrade the python3.5 to python3.6 using below steps:后来我使用以下步骤将python3.6 python3.5

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

After the installation, I made sure that running python3 is invoking the python3.6 and not python3.5 :安装后,我确保运行python3是调用python3.6而不是python3.5

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

sudo update-alternatives --config python3

After this if I type in python3, it launches python3.6 .在此之后,如果我输入 python3,它会启动python3.6

Then I reinstalled all the python packages I required using sudo pip3 install <name> (this time it was getting installed in python3 (python3.6). After this when I ran my application, it started giving me below error:然后我使用sudo pip3 install <name>重新安装了我需要的所有 python 包(这次它安装在 python3 (python3.6) 中。之后当我运行我的应用程序时,它开始给我以下错误:

Traceback (most recent call last):
  File "app.py", line 12, in <module>
    from PyQt5 import QtGui, QtCore, QtWidgets, QtPrintSupport
ImportError: cannot import name 'QtGui'

With python3.5 it was working perfectly fine but with python3.6 it started showing this error.使用 python3.5 它工作得很好但是使用 python3.6 它开始显示此错误。 How can I resolve this issue.我该如何解决这个问题。 Thanks谢谢

I think the I went into this issue because I upgraded the python3 from 3.5 to 3.6 so I believe some path got messed up and it wasn't able to locate the pyqt5 properly.我认为我遇到这个问题是因为我将 python3 从 3.5 升级到 3.6,所以我相信有些路径搞砸了,它无法正确定位 pyqt5。

I installed pyqt5 using apt-get install python3-pyqt5 .我使用apt-get install python3-pyqt5 pyqt5 So I installed it using pip:所以我使用 pip 安装它:

pip3 install pyqt5==5.14.0

and it worked fine.它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM