Qt platform plugin fails to load for other computers - python

I have created an .exe from a python app with pyinstaller in Windows. This app opens some matplotlib windows. At first, at the opening of the matplotlib windows, it throwed me the error "This application failed to start because it could not load the Qt platform plugin 'Windows'". I did some digging around and found out that I had to set an enviromental variable 'QT_PLUGIN_PATH' to the value 'C:\Users\user\Miniconda2\Library\plugins'. It worked right but on my PC only. When I open the .exe in other PCs and open the matplotlib windows, it shows me the same error. Is there a way to make it work for every computer?

you need to package QT DLLs with the installer. These DLL's must be shipped with your app because your app has dependency on them. It works on your PC because you have QT packages installed on your machine.
Please follow the link below to see the sample code in order to create package that resolves the DLL issue.
https://github.com/carlosperate/pyinstaller-test/blob/master/package/pyqt5_test.spec

They say, if you can't untie the knot, cut it out. That's what I did because I could not figure out a way, so I completely removed the Qt backend and added a Tk one with this line:
import matplotlib
matplotlib.use('TkAgg')

Related

Matlab error: Not find Qt plataform plugin 'windows'

I'm running a python function in Matlab and when I run I got the error:
This application failed to start because it could not find or load the
Qt plataform plugin 'windows' in '' '' , Available plugins are:
minimal offscreen, windows. Reinstalling the application may fix this
problem.
I already followed the steps in this video copying the platform folder to pyqt tools and in this post add to the environment path.
If I run my code in python it works fine, It seems that Matlab is not finding the Qt platform plugin 'Windows'
Someone can help me, please?
This is the problem of deploying Qt applications. Depending on platform you're using you can find tool for deploying, it is in Qt directory. For example, on my PC with Windows this is:
c:\Qt\5.15.0\mingw81_64\bin\windeployqt.exe
You can call this tool like this:
windeployqt <path-to-app-binary>
// OR
windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>
There are many other options like --debug, --release, etc. Too see all of them, just call windeployqt.
On other platforms it could be linuxdeployqt, macdeployqt, also pyqtdeploy.
After calling this tool it will copy all required submodules to (near) your app, so it will find all it needs.
On my Windows system, I had the same experience that the Python function ran natively, but would not run via MATLAB. The problem was missing or incompatible dlls (not exe) files. To solve the problem I copied the exact dlls from my conda environment into the MATLAB \bin\win64 folder. That is, I copied these five dlls
qdirect2d.dll
qminimal.dll
qoffscreen.dll
qwebgl.dll
qwindows.dll
from the \Library\plugins\platforms folder of my conda environment
C:\Users\username\AppData\Local\Continuum\envs\myenv\Library\plugins\platforms
into the MATLAB folder
C:\Program Files\MATLAB\R2020b\bin\win64\platforms
While doing the copy, I overwrote three dlls which already existed in the MATLAB folder.

ImportError: DLL load failed while importing QtCore, QtGUI

I just upgraded my Python to 3.8.3 and pyside2 to 5.15.0 and now it's showing me:
from PySide2 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed while importing QtCore: The specified module could not be found.
My Environment variables are in the path and I have the latest version of both Python and PySide2...
Why is this happening??
I tried reinstalling PySide2 but nothing happens...
I think you failed to install it. Probably it collides something...
I updated PySide6.2.4 → 6.3.0 today. I run into this error again.
In my case, QtWidgets...
On windows, we usually have Local files and Roaming files.
My installation leads my files into Local files, but I don't know why, Roaming file also has python file. And the file has site-packages , naturally Pyside6.2.4 was in it. So I removed the python file in Roaming.
And then, I reinstalled PySide6. Installation itself is no problem, error didn't occur. (Because Local files already have python file which has site-packages containing Pyside6... installation had no effect.)
But I checked the installed folder, the number of files seemed to be less than usual... there are no characters like QtWidgets...
In spite of reinstalling again, the condition never changed.
I read commandline message carefully, I found out I installed other files at the same time. PySide6_Addons_6.3.0.dist-info, PySide6_Essentials-6.3.0.dist-info PySide6-6.3.0.dist-info.
Because these files are not removed in the previous handling, installation seemed to be in vain.
So I deleted PySide6, PySide6_Addons_6.3.0.dist-info, PySide6_Essentials-6.3.0.dist-info PySide6-6.3.0.dist-info all.
After that, I reinstalled PySide6.3.0. My installation sucessed.
In general, if we downloaded a python, we would download from python.org
You can download it into any drive.
If you download python, python automatically makes a Lib module at the same directory.
And then, you must set a pass for them.
I don't make sure which directory to add, it will be necessary procedure.
In my environment system path environment as follows:
Scripts module will be created for mainly command-script.
For example, they will have pyside2-rcc.exe or pyside2-uic.exe, and pip.exe.
I was warned when I made Qt-resource file because of the lack of path.
If you can't do pip, you may be able to do the same thing by writing py -m command in front of the pip command.
Moreover, if you installed PySide2, you should install into the site-packages belonging to the same directory of python.exe.
You go into the directory python.exe exists with command-prompt, you command pip the PySide2 module.(from .whl will be better)
After that, site-packages module of the Lib module will get the PySide2 packages.
For the test, I recommend you boot Python IDE and write "from PySide2 import QtCore, QtWidgets, QtGui and other codes.
Even if you follow my introduction, you may have the same problem.In that case, it is possible to be a time for transition of some other environments.
For example, AFAIK, PySide6.0 couldn't use QtWebEngine .But with PySide6.2 makes it.
I ran into the same problem when I was using Spyder with Anaconda, and I couldn't find out what is the reason. I don't make sure whether QtWebEngine can be used with Spyder with PySide6.2 even now because Anaconda can't use PySide6.x yet.AFAIK, PySide5.15 couldn't use QtWebEngine.
At any rate, I think we should know the basic, minimal environment for using python & pyside.
Anaconda is very useful, but I had no exact knowledge about controling directories for python, I was very confused.Sometimes, there may be also the problem at the spider side. (In addition to it, Anaconda recommends conda, but I often want to use pip.)I couldn't distinguish where the problem was.It makes me more confused.I have been trying to solve this problem in only the Anaconda environment.
For that reason, I think this basic installation will be a good mark.If we can execute python with this basic environment, the problem is in your
package controller.Otherwise, we cannot help waiting for the time to solve it.
I also ran into this problem.
I couldn't execute my code as it is.
When I update my Anaconda3 for python3.7.x to python3.8.3., and update my PySide2,
this error hannpened.
I have followed this solution:
https://bugreports.qt.io/browse/PYSIDE-1323
Thanks to this, I could unexpectedly do 'from PySide2 import QtCore, QtGui, QtWidgets' on the Anaconda Prompt, console.
Nonetheless, I have the same error on the spyder, IPython.
I couldn't understand why it is. I couldn't execute codes from Spyder, but I can execute from Anaconda Prompt...(It seems to me they are the same thing, on the surface at least.)
So, as my final way, I changed the current console to an external console.
It is just the same to be executed from Console Application attached by Windows.
(>python module_name.py)
I could execute my file by this way... (But unvisible errors came!)
Until this bug is repaired, I execute my file by an external console.

Why PyCharm not importing/detecting OpenCV, which compiled and installed from source?

I have compiled and installed OpenCV from source, and it works perfect, importing and using it in IDLE IDE or CMD working well.
But when using PyCharm to import OpenCV, there are no errors, but it is warning me that the function or OpenCV variables, can not find.
It is a screenshot from the PyCharm IDE:
There is a warning that imread() function not found.
In the IDE Settings, I did not find any way to configure the OpenCV, all settings seem OK, one more screenshot:
So this problem caused IDE does not autocomplete or suggest the parameters and so on...
But when running the program, it works well without any problem.
Note: When installing OpenCV with PyCharm IDE add packages, then it is OK. But I need to use the one which is compiled from source and installed locally.
Edit:
This the screenshot of IDLE IDE, which you can see the autocomplete works well.
List of packages:
In this list, there is no cv2, which the other packages in the dir are listed here
I had exactly this problem with OpenCV 4.2.0 compiled from sources, installed in my Conda environment and PyCharm 2020.1.
I solved this way:
Select project interpreter
Click on the settings button next to it and then clicking on the Show paths for selected interpreter
adding the directory containing the .so cv2 library (in my case in the Conda Python library path - e.g. miniconda3/lib/python3.7/site-packages/cv2/python-3.7). In general check the site-packages/cv2/python-X.X directory)

PyCharm and PyQt5 unresolved reference but working

I have installed PyQt5 using the windows installer. I have tried creating some windows and stuff and it works great. Still, pycharm seems to not like PyQt5 very much, and is marking errors everywhere in my code.
As I said, PyQt5 is working great, but it's kind of annoying to have those errors which, by the way, i can not alt + enter + ignore them.
I guess it's just a matter of adding references or something to pycharm, but I have no idea how to do it and I have already spent 1 hour trying to look for solutions in stack-overflow, and none of them work. I have also tried re-installing it.
I am using windows 7 64 bits, python 3.4, and PyQt5 of 32bits because 64 didn't work for some reason.
I had similar problem because I had both PyQt4 and PyQt5 installed.
In general this can cause all sorts of problem, so the spyder-ide guys made the qtpy package, which gives an abstraction on top of the PyQt5/PyQt4/PySide.
Nowdays the qtpy is a standard library in the Anaconda distribution, and you can call it instead of PyQt5/PySide likes this:
from qtpy.QtCore import QFile, QFileInfo
from qtpy.QtGui import QIcon, QKeySequence, QPixmap
It solved me this specific problem in PyCharm.
I also have both 32 bit and 64 bit Python v3.5 and PyQt5 versions installed. That should not matter because I installed the 32 bit PyQt5 package in the 32 bit PI and the 64 bit PyQt5 package in the 64 bit PI. I installed the PyQt5 packages from Riverbanks's PyQt5 web site. Christopher Gohlke does not have them yet on his Windows extensions site, nor does PyCharm's PI dialog even list PyQt5 as an available package.
PyCharm does indeed incorrectly flag numerous warnings whether I choose the 32 bit PI or the 64 bit PI for the PyQt5 project I am working on. This appears to be a cosmetic bug only for PyQt5 code, since the code does run correctly, even if I run the code from PyCharm's Terminal window. Also, note that PyQt5 is not listed in PyCharm's PI settings dialog, even though Windows 10 File Explorer does indeed list the proper packages in the proper site-packages folder. Doing a PyCharm Invalidate/Restart does not help.
That said, you do not have to, nor should you, suppress warnings for everything. Just suppress warnings on a case by case basis only for PyCharm's incorrect PyQt5 warnings. You can do it like this:
def __init__(self):
# noinspection PyArgumentList
super().__init__()
In my case I needed in my PyCharm to go File -> Settings -> Project: MyProject -> Project structure and chose correct Project Interpreter
Another probable and easy means is to:
open the command prompt as an administrator
type in 'pip' (without the quotes)
type in: pip show PyQt5 (this shows you where PyQt5 has been installed.
follow the trace given to you from the command prompt. Now, open the folder 'site-packages' and copy every folder termed' PyQt5' to the 'lib' folder instead (ignoring those with '.. - info' is inconsequential).
In Pycharm or Visual studios, the red underline goes off and the problem of 'unresolved reference' is eliminated.

Making pygtksourceview work in windows

So, I'm trying to get gtksourceview python bindings work under windows (I'm developing a cross platform gtk application that shows code, so gtksourceview seemed like a natural choice).
I have pygtk installed and working (I followed the instructions in http://www.pygtk.org/downloads.html)
I tried the instructions in http://projects.gnome.org/gtksourceview/ for gtksourceview.
Here is what I did:
Downloaded and extracted the latest gtksourceview window binaries from: http://ftp.gnome.org/pub/gnome/binaries/win32/gtksourceview/2.10/gtksourceview-2.10.0.zip
The website said gtksourceview needs libxml, so I downloaded and extracted the latest libxml window binaries from:
http://xmlsoft.org/sources/win32/libxml2-2.7.6.win32.zip
Added the folders containing dll files to the PATH (in my computer they were c:\opt\gtksourceview\bin; C:\opt\libxml2-2.7.6.win32\bin)
Installed pygtksourceview with the windows installer:
http://ftp.gnome.org/pub/gnome/binaries/win32/pygtksourceview/2.10/pygtksourceview-2.10.0.win32-py2.6.exe
Renamed the file libxml2.dll to libxml2-2.dll (after running depends on the gtksourceview dll)
Now, the gtksouceview widget seems to work, until I'm trying to set the code's language. When I do that python crashes.
Here is how I crash it in the console (the simplest way i could come up with):
>>>import gtksourceview2
>>>lang = gtksourceview2.language_manager_get_default().get_language('cpp')
>>>lang.get_style_ids()
I'm hoping I'm not the first person to use gtksourceview in python on windows. Any ideas what I should try?
So in case anyone else is wondering -- I grabbed the wrong libxml dll. The right one is in:
http://ftp.gnome.org/pub/GNOME/binaries/win32/dependencies/libxml2_2.7.7-1_win32.zip

Categories

Resources