PySide2 Module Not Found
-
wrote on 5 Mar 2020, 01:36 last edited by
I am new to QT and am trying to create the tutorial Hello World application using Python and PySide 2 on Windows. When I check my PySide2 installation from the command prompt I see that I have PySide2 Version 5.14.1 installed. I can successfully import PySide2.QtCore. I can even create a QT application window directly from the command prompt. However, when I try to run the same code from a file in the QT Creator I get an error saying ModuleNotFoundError: No module named 'PySide2'. I'm not sure why QT Creator cannot find PySide2 when I know it is installed.
-
I am new to QT and am trying to create the tutorial Hello World application using Python and PySide 2 on Windows. When I check my PySide2 installation from the command prompt I see that I have PySide2 Version 5.14.1 installed. I can successfully import PySide2.QtCore. I can even create a QT application window directly from the command prompt. However, when I try to run the same code from a file in the QT Creator I get an error saying ModuleNotFoundError: No module named 'PySide2'. I'm not sure why QT Creator cannot find PySide2 when I know it is installed.
@BD4L Do you have more than one Python installation? It could be that QtCreator uses a Python installation which does not have PySide2.
-
I am new to QT and am trying to create the tutorial Hello World application using Python and PySide 2 on Windows. When I check my PySide2 installation from the command prompt I see that I have PySide2 Version 5.14.1 installed. I can successfully import PySide2.QtCore. I can even create a QT application window directly from the command prompt. However, when I try to run the same code from a file in the QT Creator I get an error saying ModuleNotFoundError: No module named 'PySide2'. I'm not sure why QT Creator cannot find PySide2 when I know it is installed.
wrote on 5 Mar 2020, 08:48 last edited by@BD4L
As @jsulm says --- you need to look at how your environment for locating PySide2 is set up.But, am I late to the party? I didn't even think you could use Creator for PySide2 development? It doesn't have a Python editor or debugger in the IDE, does it? Whenever I use it it insists on making me pick a C++ kit. I use PyCharm or VS Code for PySide2, even if I use the Designer from Creator for creating the
.ui
file. Am I missing out? -
wrote on 5 Mar 2020, 23:59 last edited by
Hi all thanks for the replies. I'll try to answer each persons questions thankss:
@jsulm - I do have a few different python installations, I assumed QT creator would default to look at the one on my main system path rather than ones that I've setup using virtual environments. How can I check in creator which python installation Creator is set to look at?
@JonB - When I create a new project in QT creator under the application project type I have two default templates for Python projects both of which try to automatically import PySide2 so I assume it's supported. If it's not I can try creating my project in VS code. I'm not sure what functionality I would lose out on using Pyside2 in VS code vs using QT creator.
@Denni-0 I'm not sure what you mean by 'design your GUI using Qt as it was meant to be used'. Qt Creator seems to be a standard IDE optimized for Qt applications so I'm not sure why it would be any better or worse than Visual Studio. Right now I"m just trying to learn Qt and Pyside but eventually I'll be using them to create a desktop (windows) application that will produce specific output files which will then be loaded into a mobile (android) app. Qt appears to be one of the languages that will work to accomplish both of those things with python, but I'm open to other suggestions.
-
wrote on 6 Mar 2020, 01:36 last edited by
Just a quick update. I ran the pip install for PySide2 in VS Code in one of my virtual environments and now the PySide2 import works just fine in QT Creator. I would be interested to know how to change what environment QT creator is looking at though. I haven't been able to find anything in the documentation.
-
Hi all thanks for the replies. I'll try to answer each persons questions thankss:
@jsulm - I do have a few different python installations, I assumed QT creator would default to look at the one on my main system path rather than ones that I've setup using virtual environments. How can I check in creator which python installation Creator is set to look at?
@JonB - When I create a new project in QT creator under the application project type I have two default templates for Python projects both of which try to automatically import PySide2 so I assume it's supported. If it's not I can try creating my project in VS code. I'm not sure what functionality I would lose out on using Pyside2 in VS code vs using QT creator.
@Denni-0 I'm not sure what you mean by 'design your GUI using Qt as it was meant to be used'. Qt Creator seems to be a standard IDE optimized for Qt applications so I'm not sure why it would be any better or worse than Visual Studio. Right now I"m just trying to learn Qt and Pyside but eventually I'll be using them to create a desktop (windows) application that will produce specific output files which will then be loaded into a mobile (android) app. Qt appears to be one of the languages that will work to accomplish both of those things with python, but I'm open to other suggestions.
wrote on 6 Mar 2020, 08:36 last edited by JonB 3 Jun 2020, 08:40@BD4L
The Qt Creator I have is 4.8.1, which is based on the Qt 5.12.2 which was released packaged with the Ubuntu 19.04 I use. It still has nothing about Python/PySide2 in it! So if yours has support for PySide2 projects I haven't seen it! I am "dubious" about how good its Python editing and debugging support will be, but that's me being cynical, I have no evidence for this :) If you are happy with those features then go ahead, a fully integrated, single environment is nice.For my part I have used PyCharm with PyQt and VS Code with PySide2. I find PyCharm a much better editing & debugging experience compared to VS Code, which personally I have been disappointed with and don't much like, but your mileage may vary. They all work fine, though, and are much preferable to a plain text editor and no IDE. In both cases if you want to design the layout in Qt Creator/Designer you have to do that outside of PyCharm/VS Code. As I said, if whatever Creator's support for Python is you are happy with it then go for it.
Your comments about Creator being a standard-ish IDE, for use with Qt, are quite correct. It has its pros & cons like any IDE. Designer does not produce any code, it just generates a
.ui
file describing exactly the layout you have made. It is thepyuic
program supplied with PySide2/PyQt which generates Python code from the.ui
. You do not even have to use it or generate any code if you do not want to, you could load the.ui
directly at run-time. Though I would recommend you do use it to generate code, it's easier to manipulate with the resulting class/code. Qt was always as "meant to be used" via the Designer as with direct, dynamic widget creation. The codepyuic
generates is fine, and perfectly intelligible, and corresponds to the C++ code which would be produced fromuic
.I have done both non-Designer dynamic creation and static creation via
uic
generated code. Again, pros & cons to each. Certainly as a beginner to Qt the Designer gives you a good start.Both PySide2 and PyQt are essentially just Python language bindings to the supplied Qt C++ libraries, offering one-to-one correspondence against the methods exported from Qt. No more and no less.
-
@BD4L
The Qt Creator I have is 4.8.1, which is based on the Qt 5.12.2 which was released packaged with the Ubuntu 19.04 I use. It still has nothing about Python/PySide2 in it! So if yours has support for PySide2 projects I haven't seen it! I am "dubious" about how good its Python editing and debugging support will be, but that's me being cynical, I have no evidence for this :) If you are happy with those features then go ahead, a fully integrated, single environment is nice.For my part I have used PyCharm with PyQt and VS Code with PySide2. I find PyCharm a much better editing & debugging experience compared to VS Code, which personally I have been disappointed with and don't much like, but your mileage may vary. They all work fine, though, and are much preferable to a plain text editor and no IDE. In both cases if you want to design the layout in Qt Creator/Designer you have to do that outside of PyCharm/VS Code. As I said, if whatever Creator's support for Python is you are happy with it then go for it.
Your comments about Creator being a standard-ish IDE, for use with Qt, are quite correct. It has its pros & cons like any IDE. Designer does not produce any code, it just generates a
.ui
file describing exactly the layout you have made. It is thepyuic
program supplied with PySide2/PyQt which generates Python code from the.ui
. You do not even have to use it or generate any code if you do not want to, you could load the.ui
directly at run-time. Though I would recommend you do use it to generate code, it's easier to manipulate with the resulting class/code. Qt was always as "meant to be used" via the Designer as with direct, dynamic widget creation. The codepyuic
generates is fine, and perfectly intelligible, and corresponds to the C++ code which would be produced fromuic
.I have done both non-Designer dynamic creation and static creation via
uic
generated code. Again, pros & cons to each. Certainly as a beginner to Qt the Designer gives you a good start.Both PySide2 and PyQt are essentially just Python language bindings to the supplied Qt C++ libraries, offering one-to-one correspondence against the methods exported from Qt. No more and no less.
wrote on 6 Mar 2020, 18:29 last edited by@JonB My Qt version is 5.14.1 so maybe the Python support in creator is relatively new. So far its worked and doesn't require me to setup different virtual environments for different Visual studio applications which was causing me a headache. I'm actually more worried about the Qt debugging support than python. I have the backend of my code in python mostly done it's getting the code bound to a GUI that I'm trying to figure out, so hopefully the Qt creator can help me with that part. But thanks for all your advice.
@Denni-0 I was able to run this code in my project by replacing from PyQt5.QtWidgets with from Pyside2.QtWidgets in the import statment. The rest of the code worked as is. I think the confusion might be that I'm not using Qt Developer just Qt creator, so I'm not trying to get it to auto-generate the code, just using it as an IDE to write my own. I'm always open to ideas and suggestions though. Thanks for all the great info so far.
1/7