Virginia | 2020-05-17 19:52:07 UTC | #1
After another website suggested using PySide2 to solve an issue I am having with system tray icons not responding, I installed PySide2. However, I am unable to import anything from it. If I try to import anything from PySide2 I get the following error:
ImportError: DLL load failed: The specified procedure could not be found.
I can see from searching the web that this error message sometimes has to do with combinations of packages or other software that needs to be installed, but haven't found a solution. How do I get PySide2 working on my computer? I'm using Windows 10 and have Spyder, PyCharm, and Jupyter Notebook IDE's available.
martin | 2020-05-17 20:06:22 UTC | #2
You can have PySide2 and PyQt5 installed at the same time, the only problem is if you try and import both at the same time.
Are you trying this in Spyder by any chance? Spyder is built with Python & Qt. It can use either PyQt or PySide, but defaults to PyQt5 if it is installed. That might mean PySide2 won't work. You can override this by setting a
QT_API environment variable to e.g. 'pyside2'.
As before if you can try importing PySide2 in Python run from the command line (you can do it in a shell) you can exclude any problems with the IDEs.
Virginia | 2020-05-18 15:32:30 UTC | #3
Thank you for this information. Do you mean that I can't even have both installed at the same time? I did not try to import both at the same time, but the first time this happened I had just run the same program with importing PyQt5. The error message has now changed to one about needing only one instance of QApplication. From here https://stackoverflow.com/questions/50259785/unable-to-see-app-windows-created-by-pyside2-in-spyder it appears that this problem might apply to other IDE's that use ipykernel - certainly I get the same errors in Jupyter Notebook, which are "# You need one (and only one) QApplication instance per application." and "No module named 'PySide2.QtWidgets'; 'PySide2' is not a package." Thank you also for the link. I can see from that link and from the post on StackOverflow that they recommend using QtPy. I don't entirely understand from the link how I would use QtPy in my System Tray example. I tried to edit my code based on what was in the link, setting the environment variable, but got this error: 'No Qt bindings could be found.' Did I misunderstand what was written on that site? How would I edit the System Tray Icon example code to use PySide2 instead of PyQt5 in Spyder? Or is it not worth trying, since I can do it elsewhere? Thank you again for all your help!
martin | 2020-05-20 14:19:30 UTC | #4
[quote="Virginia, post:3, topic:202"] Do you mean that I can’t even have both installed at the same time? [/quote]
No, I mean the opposite -- it's perfectly fine to have both installed at the same time.
The issue with Spyder is simply that it itself is built using Qt and defaults to PyQt5. If you try and run PySide2 code inside Spyder, Spyder has already imported PyQt5 so PySide2 won't work.
I wouldn't recommend using the Jupyter notebook for doing GUI development, since it's based around a long-running kernel. Ideally you want to run PyQt apps as a separate process -- either from the command line, or running as a file in an IDE.
This might explain the other issues you had with Spyder actually -- how exactly are you running the code in Spyder? I see it has an internal console https://docs.spyder-ide.org/internalconsole.html but as it says there
all the commands entered in the Internal Console are executed in the same process as Spyder’s.
Since this process keeps running after you exit your app it would explain the icon sticking around.
Virginia | 2020-05-21 15:48:03 UTC | #5
I haven't been able to access the internal console. My version of Spyder does not have the same dropdown menu and when I opened Spyder using the --multithread command as instructed it looked exactly the same, and behaved exactly the same. I've also seen on Stack Overflow that Spyder had a console which was discontinued after version 3.1.4: https://stackoverflow.com/questions/45960590/how-to-add-python-console-in-spyder I'm not sure if I'm trying to open it wrong or if it is indeed wrong, since the link you sent me does seem to refer to Spyder 3. I will probably just need to use other IDE's for this kind of thing and use Jupyter or Spyder for other types of programs.
[[ discount.discount_pc ]]% OFF for [[discount.description ]] with the code [[ discount.coupon_code ]]