0

So, I have a .py file:

from PyQt4.QtGui  import *
from PyQt4.QtCore import *

When I'm executing it - I have this error message:

Traceback (most recent call last):
  File "kek.py", line 1, in <module>
    from PyQt4.QtGui  import *
ModuleNotFoundError: No module named 'PyQt4.sip'

I've tried to install sip itself, I've installed Qt4, PyQt4 and it doesn't works. Help me, guys

Curlindus
  • 3
  • 1
  • 2

1 Answers1

1

I've tried to reproduce your error and in fact I succeeded in doing that. I have a Debian system, so I used apt to install all the packages I wanted to install.

I tried to run in an interactive python environment (sorry for the bad terminology, I'm not proficient in python: I used it only a few times to solve very simple math problems) the code

from PyQt4.QtGui import *

and it did not work.

The first try to solve the problem was installing the packages pyqt4-dev-tools and pyqt4.qsci-dev, which did not solve the problem. So I tried to install the package python-qt4, which happened to be already installed in my system. Then I tried to install python-qtpy, which did not work either. Then I stumbled upon this question on StackOverflow, which gave me the idea that I was using the wrong python version (by default I use python 3.7), so I tried to run the aforementioned command in a python 2.7 and it worked.

Now, because I was disappointed by the lack of support of python 3, I tried to look for some other packages about qt and python 3 and I found python3-qtpy. I installed it and the command... still did not work. However, while it was installing, I noticed that it was installing the version 3 of the qt libraries, so I tried to run, in the interactive python 3 environment, from PyQt5.QtGui import * and it worked.

Some notes: I saw that it also installed python3-sip together with python3-qtpy and that I've already installed on my system the package python-sip; not sure if this helps. Another note I want to make is that I use Debian, but you did not specify your distribution. This wouldn't in general be a problem as python should not be dependent on the OS it's running on, however, having used apt and the Debian repos to install all the required dependencies might be an influencing variable in the solution of the problem. As I mentioned before, I rarely use python, but I know you can use pip to install new "packages" or the StackOverflow answer uses brew. The only thing to check is the python version you install your packages for. EDIT: If you need it, have a look at python qtpy version 4 on pip and python qtpy version 5 on pip

Now, I tried to be as detailed as possible in explaining what I did to solve the import problem, but if you have some more question, feel free to add a comment below.

Hope this helps.

LuxGiammi
  • 347
  • 1
  • 2
  • 12
  • Thank you for your answer. All that you've explained worked. I've tried to import PyQt5.QtGui and it worked! I've tried to import this libraries using Python2 and it also worked! But I need to use PyQt4 on Python3, not PyQt5 on Python2. I need it for an IDE called uPyCraft and main file - uPyCraft.py contains this two lines of code that I've described above. So, this IDE uses PyQt4 and Python3. https://github.com/DFRobot/uPyCraft_src - here's a link. I've installed all the packages that you specified but it didn't work. Forgot to mention - I'm using Ubuntu 18.04 with KDE Plasma. – Curlindus Dec 22 '19 at 18:15
  • Sorry for the delay I'm posting this. I've just finished trying to install that IDE. I'm now stuck at the "Installing QScintilla" step as described in the README.md file in the repository you linked. Although I've not solved the problem yet, I have some hypothesis on what went wrong: when I tried to install PyQt4 from the SourceForge repository, following the instructions given on the github page, I noticed that everything was installed in `/usr/lib/python2.7/dist-packages`, so they cannot be used with Python3. I'm trying to fix the problem. – LuxGiammi Dec 26 '19 at 10:09
  • @Curlindus Have a look at this issue on github https://github.com/DFRobot/uPyCraft_src/issues/11 – LuxGiammi Dec 26 '19 at 10:55
  • Wow, thank you. I've checked this issue on github and it worked! I've also checked `/usr/lib/python2.7/dist-packages` and that's interesting. Thank you for your help. It was very important for me. – Curlindus Dec 26 '19 at 15:20
  • @Curlindus You're welcome! :-) – LuxGiammi Dec 26 '19 at 15:46