QWebEngineView not working with PyInstaller - pyqt5

I'm getting a "blank canvas" when using PyInstaller to package and application that utilizes QWebEngineView. Any help would be greatly appreciated!
Here's some code to reproduce the problem...
The following code runs fine with python:
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QWebEngineView()
view.resize(1024, 600)
view.load(QUrl('http://www.google.com'))
view.show()
sys.exit(app.exec_())
but after packaging with pyinstaller toy.py nothing is shown.
The python application shows:
while the pyinstaller application shows:

So this appears to be a bug in pyinstaller that can be patched by creating a specific file for PyQt.
The first clue in debugging this problem is to take note that QtWebEngineProcess.exe starts (as seen in the Task Manager) when we start from python, but it does not start with our application with pyinstaller. Upon inspection a log is written next to the pyinstaller copy of the QtWebEngineProcess.exe that doesn't really give a helpful message, but it does give a clue that the *.exe was attempted to start and crashed.
It appears that adding a qt.conf to dist/<app>/PyQt5/Qt/bin with the contents
[Paths]
Prefix = ..
fixed my problem.

Related

Send help in the form of someone who knows python well

I am currently well versed in java, but I am trying to get into python. I know the basics, but am struggling with package use and implementation into source code.
I have successfully installed both numpy and Pillow (or PIL):
Click here for cmd telling me both packages have been installed
When I typed import numpy into cmd running python, it worked no problem, but now I've tried to open IDLE and import it there, and written source code trying to import it and utalise parts of the numpy lib but it always gives me a ModuleNotFoundError
python idle shell import vs. cmd import
My folder layout is a little wacky:
C:
..Users
....B
......ForImagingProject
........PYTHON
..........(python standard subfolders)
..........Lib
............site-packages
..............numpy and PIL and pip here
Any and all help would be appreciated
Thanks ~ B
EDIT: I messed up and my IDLE shortcut was running idle.pyw instead of idle.bat. Everything working smoothly now.
Check your IDLE's python executable. Is it the same one as in your cmd prompt?
The easiest way to check is to run this:
import sys
print(sys.path)
Look for something like
'PATH_TO_PYTHON/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7'or
'PATH_TO_PYTHON/Frameworks/Python.framework/Versions/2.7/lib/python2.7'
Make sure this is the same in both the IDLE and in cmd.
The reason the shell I was working in was unable to recognize the module was because my IDLE shortcut was mapped to idle.pyw instead of idle.bat. Everything running smoothly now

import matplotlib.pyplot crashes on jupyter notebook

I have a jupyter notebook running on a remote cluster to which I have set up an ssh tunnel. Everything was working fine till today. Now everytime I do :
import matplotlib # This works
%matplotlib inline # This causes kernel to restart
import matplotlib.pyplot # This also causes the kernel to restart
Running a standalone ipython interpreter and doing :
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot ## Leads to Core dumped : Segementation Fault
Running the same on a python interpreter works fine.
Jupyter version : 4.1.1
Python version : 2.7.7
Any help would be much appreciated.
Thank You
Often, this kind of error seems to be related to the backend. Have you tried any other backends? Do these result in the same error? Like this we could narrow down the source of the error.
(I don't have a remote cluster, so I can not reproduce it.)
You can find available backends as described here.
I perhaps have the same problem but on my local machine. I got into jupyter3-qtconsole 4.2.1 with Python 3.4.5 and IPython 5.0.0. and enter
`%matplotlib
Using matplotlib backend: Qt4Agg`
the error message (shortened):
File "/usr/lib64/python3.4/site-packages/tornado/ioloop.py", line 603, in _run_callback
ret = callback()
and finally
from IPython.core.interactiveshell import NoOpContext as context
ImportError: cannot import name 'NoOpContext'
Same thing happens in a notebook but in a straightforward IPython terminal, everything runs OK
Hope this is helpful to someone

OMP warning when numpy 1.8.0 is packaged with py2exe

import numpy
When I packaged above one line script as a single executable window application using py2exe, I get following warnings upon launch.
OMP: Warning #178: Function GetModuleHandleEx failed:
OMP: System error #126: The specified module could not be found.
This warning happen only when I build as single executable (i.e., only when bundle_files=1). Here's my setup.py for this.
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1}},
windows=['testnumpy.py'],
zipfile = None,
)
This problem started with numpy 1.8.0. When I revert back to 1.6.2, the warnings don't show up.
Usually a single executable packaged by py2exe will catch warnings and traceback and save them into a log file. But somehow these warnings are not captured and the app creates a console window to show warning. I want to suppress this additional console window to show up.
How can I fix this warning problem?
What I tried (nothing worked):
I tried this redirecting sys.stderr.
I searched github numpy source for openMP assuming the OMP stands for it as mentioned here. But, nothing useful came out.
I have copied libiomp5md.dll to the same folder as setup.py.
I tried filterwarnings:
I tried sys.excepthook.
As I wrote in the comment, installing numpy 1.8.1rc1 from sourceforge did fix the issue, although I don't really know the differences...
I had this issue with numpy 1.13.1+mkl and scipy 1.19.1. Reverting to numpy 1.8.1rc1 is not an acceptable solution.
I tracked this issue to the scipy.integrate subpackage. The warning message pops up when this package is imported. It seems that perhaps libraries that use MKL don't like being invoked from library.zip, which is where py2exe places packages when using bundle option 2.
The solution is to exclude scipy and numpy in the py2exe setup script and copy their entire package folders into the distribution directory and add that directory to the system path at the top of the main python script.

PyInstaller --onefile throws Qt error with pandas, matplotlib and sklearn

Using PyInstaller with the --onefile flag, I can successfully build the following script into a .exe:
import sys
from PyQt4 import QtGui
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('Ready')
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Statusbar')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
I get the warnings below when building: (for readability I use "PYINSTALLERDIR" to replace the full path, which is "C:\Users\name\Downloads\pyinstaller-pyinstaller-v2.0-544-g337ae69\pyinstaller-pyinstaller-337ae69\".
PYINSTALLERDIR>pyinstaller.py --onefile --log-level=WARN MainWindowHello.py
1306 WARNING: library python%s%s required via ctypes not found
1468 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
2957 WARNING: library python%s%s required via ctypes not found
But the outputted 14 MB .exe runs fine and displays a Qt window. However, when I try to add pandas, matplotlib or sklearn, I run into problems with Qt.
Adding either import matplotlib or import sklearn to line 3 of my script gives me these warnings when building:
PYINSTALLERDIR>python pyinstaller.py --onefile --log-level=WARN MainWindowHello.py
1371 WARNING: library python%s%s required via ctypes not found
1528 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
3051 WARNING: library python%s%s required via ctypes not found
27108 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executable
33329 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
When I try to run the resulting .exe (44 MB for matplotlib, 87 MB for sklearn), no Qt window is displayed and I get this error message:
WARNING: file already exists but should not: C:\Users\name\AppData\Local\Temp\_MEI75002\Include\pyconfig.h
Traceback (most recent call last):
File "<string>", line 2 in <module>
File "PYINSTALLERDIR\PyInstaller\loader\pyi_importers.py", line 409, in load_module
ImportError: could not import module 'PySide.QtCore'
With import pandas at line 3, I get the same warnings (as well as warnings about libzmq.pyd, but I have gotten them earlier with working programs). When I try to run the 119 MB .exe, the program crashes and throws the following error:
WARNING: file already exists but should not: C:\Users\name\AppData\Local\Temp\_MEI85162\include\pyconfig.h
Sub class of QObject not inheriting QObject!? Crash will happen when using Example.
I have tried with both PyInstaller 2.0 and the dev version. All three scenarios work well when using the default --onedir instead of --onefile. Can anyone help me figure out what goes awry when using --onefile?
UPDATE: I tried building with pandas in PyInstaller 2.1 and I still get the same error when using --onefile. Again, everything works when not using --onefile.
I was having the same issue with a script where I was importing PyQt4 as well as some modules that were importing PySide. PyInstaller worked fine with the --onedir option (the default), but I was getting ImportError: could not import module 'PySide.QtCore' when using the --onefile option.
After reading this I tried adding 'PySide' as an exclude in my spec file to force exclusive use of PyQt4 and the exe now runs fine. The modules you've listed should work fine with PyQt4 so it should hopefully solve your issue too.
Also, while it's not a huge problem, a solution to the file already exists warning is described here. Just add these lines in the spec file after a = Analysis... to remove the duplicate that causes the warning:
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break

Error with dll when importing Qt Desktop Components for PySide

I am trying to get Qt Quick Desktop Components to work with PySide 1.1.2 and Python 2.7. So far, I have compiled the latest version of the Desktop Components with MSVC in release mode and copied the components folder, containing both the .qml files and plugin/styleplugin.dll, to Python\Lib\site-packages\PySide\imports\QtDesktop.
Here is my current code:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import QDeclarativeView
app = QApplication(sys.argv)
view = QDeclarativeView()
view.setSource(QUrl('server.qml'))
view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.show()
sys.exit(app.exec_())
My Qml file:
import QtQuick 1.1
import QtDesktop 0.1
Window {
}
The error I am getting:
file:///C:/Programming/CibAbi/server.qml:15:1: plugin cannot be loaded for module "QtDesktop":
Cannot load library C:/Programming/Python27_32bit/Lib/site-packages/PySide/imports/QtDesktop/plugin/styleplugin.dll:
The specified procedure could not be found.
import QtDesktop 0.1
^
Does anybody know of a way to fix this, or does anyone have more specific steps on using the Desktop Components with PySide? Thank you. :)
Edit your system PATH variable so that the PySide directory appears in the path before any PyQt or other Qt directory.
http://qt-project.org/wiki/PySide_FAQ#6624847b60a84a6d81a5950805dfb6df
works perfectly
pyside py 3.3 32 Bit
Qt libraries 4.8.5 for Windows (VS 2010)
config release and build
rename folder "component" to "QtDesktop"
copy this folder en pyside/imports/
and Guala