2

I am using Python Tools for Visual Studio 2013. Now I also want to use PyQt for my User Interface.

I successfully installed PyQt and used it in other IDEs (e.g. PyCharm). Now I want to import PyQt in Visual Studio 2013, but it down't work.

This code

from PyQt import QtGui

print('Hello World')

leads to the following error:

No module named 'PyQt'

I already added Qt.pyd, QtCore.pyd and QtGui.pyd to the References of my Python project in Visual Studio 2013. But still, the PyQt cannot be found and is also not detected by Auto-completion.


Update

Shadow9043's advice solved the problem. However, I still got no code-completion for the PyQt classes. I get warnings when importing (Unable to resolve "PyQt") and I don't get the list of members when using PyQt classes.

Is there anyway to get VS2013 to "know" the PyQt classes?

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
Exa
  • 4,020
  • 7
  • 43
  • 60

1 Answers1

1

You are getting your import statement wrong.

Using python shell with:

>>> from PyQt import QtGui
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    from PyQt import QtGui
ImportError: No module named 'PyQt'

To fix this you need to specify the PyQt version on the import. See below:

from PyQt5 import QtGui  # For PyQt5
from PyQt4 import QtGui  # For PyQt4
Shadow9043
  • 2,140
  • 1
  • 15
  • 13
  • Thank you, I will try this when I'm back at home. Oddly, it works with `from PyQt` in PyCharm. Also, VS doesn't give any import suggestions (auto-complete) for the PyQt libs. Not for `PyQt4` either. – Exa Oct 17 '14 at 13:49
  • When I type a PyQt class and enter `.` I get a tooltip saying "The completion DB needs to be refreshed.". So I open the Python Environments window and wait for the DB to be refreshed. But it never does. The loading bar of "Refreshing DB" loads until about 60% and then stops. – Exa Oct 18 '14 at 01:46
  • Do you have some information on my last comment? It seems to be stuck at "Analyzing standard library". – Exa Jan 13 '15 at 21:58