While attempting to "freeze" a Python (v2.78) app which uses PyQt4 (v4.10.4) and Matplotlib (v1.4.2) under Windows XP SP3, using PyInstaller (v2.1), I am running into an annoying problem.
At the very beginning of my program, I have the following lines:
import matplotlib
matplotlib.use("Qt4Agg")
matplotlib.rcParams["backend.qt4"] = "PyQt4"
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
When I run PyInstaller using the line:
pyinstaller --noconsole --icon=app.ico App.py
the application is correctly frozen into the "dist" folder and it runs without any hassles. The problem is, a lot of unwanted files are included into the distribution folder! By these "unwanted" files, I refer to the several "wx" modules which are obviously useless to my application (since it uses Qt and not Wx for the UI). If I manually delete these files from the dist folder, the app still runs very well.
So, my big question is: how do I get rid of these unwanted files when freezing the app with PyInstaller?
I could find several possible solutions for similar problems with py2exe and cx_Freeze, but nothing that refers to PyInstaller (and these is my preferred "compiler" because it has been the only cross-platform one that seems to work very well under Windows and Linux).
Thanks in advance for any assistance you can provide!
EDIT: Also, when running PyInstaller, I got an ugly error message:
43592 INFO: Processing hook hook-matplotlib
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_webagg.py", li
ne 30, in <module>
raise RuntimeError("The WebAgg backend requires Tornado.")
RuntimeError: The WebAgg backend requires Tornado.
But of course I am not using any WebAgg backend (and have no idea what the heck is "Tornado"!).
By the end of the freezing process, I got a warning:
265046 WARNING: lib not found: gdiplus.dll dependency of C:\Python27\lib\site-pa
ckages\wx-2.8-msw-unicode\wx\wxmsw28u_core_vc.dll
I also would like to get rid of both messages, during the freezing process (which I presume I will be, when the problem of getting rid of unwanted backends is solved)!
"
Related
I would like to install PySide2 on my Windows 10, Python version 3.8, despite the wheels not being released for it yet.
Naturally, I have first tried the pip install --python-version 3.7 command to see if simply getting everything, but for the previous Python version, would be fine. It didn't work.
So instead I installed QT on my machine as well as every required dependency and tool to build it manually. I have progressed quite far and managed to successfully build shiboken2, but failed to build PySide2 itself.
The errors I keep getting are about missing DLL-s when trying to import shiboken2. Unfortunately, the output is rather unhelpful as it doesn't actually tell me which ones are missing, and I couldn't figure that out on my own.
The error from the manual building is as follows (nmake command in C:\PySide2\pyside-setup\pyside3_build\py3.8-qt5.12.6-32bit-release\pyside2 directory):
Scanning dependencies of target QtCore_pyi
Traceback (most recent call last):
File "C:/PySide2/pyside-setup/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 294, in <module>
generate_all_pyi(outpath, options=options)
File "C:/PySide2/pyside-setup/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 251, in generate_all_pyi
import PySide2
File "C:\PySide2\pyside-setup\pyside3_build\py3.8-qt5.12.6-32bit-release\pyside2\PySide2\__init__.py", line 51, in <module>
_setupQtDirectories()
File "C:\PySide2\pyside-setup\pyside3_build\py3.8-qt5.12.6-32bit-release\pyside2\PySide2\__init__.py", line 21, in _setupQtDirectories
import shiboken2
ImportError: DLL load failed while importing shiboken2: The specified module could not be found.
I would normally wait patiently until the wheels are released, but I can't find any information on the progress for Windows, and I know the library is available for Python3.8 on other platforms.
Do you recommend any steps to find out what's wrong with my build (I would normally use pip install for PySide2 so this is all new to me), or know how to solve the problem directly? I know shiboken2.cp38-win32.pyd is there and I've also included it in my PATH env var just in case, same for shiboken2.cp38-win32.dll - but these don't seem to be the missing files.
Note: Should this be a Super User question (?)
On Windows platform simple pip install PySide2 is not enough, you should make post-install steps. As part of PySide2 installation you got pywin32_postinstall.py script (Not sure about Win10, but on Windows 7 the path is C:\Users\<your_user>\AppData\Local\Programs\Python\Python38\Scripts\)
You should run pywin32_postinstall.py -install to register DLLs.
I had a simple app up and running that used the PyGui package. After I decided I had everything working I refactored my code and basically broke it up over multiple files, but I am fairly sure I did not change the location of any files. Now when I try to run my app It gives me the following error:
Traceback (most recent call last):
File "blobedit.py", line 16, in <module>
from GUI import Application, ScrollableView, Document, Window, Cursor, rgb
File "/Users/<myusername>/Desktop/BlobEdit/GUI/__init__.py", line 54, in <module>
raise ImportError("Unable to find an implementation of PyGUI for this installation")
ImportError: Unable to find an implementation of PyGUI for this installation
I have tried moving files around for weeks and can't find the problem. Any help would be much appreciated!
You have a directory GUI and inside it __init__.py, this makes the directory an importable package.
Unfortunately, PyGUI also provides a GUI package. Due to the way Python searches for packages to import, your GUI has come up first and this is what is causing problems.
The simple way to solve it is to rename your GUI directory /Users/Destkop/BlobEdit/GUI to something else.
I'm using py2app to make a wxPython frozen binary that uses matplotlib (whew). The resulting executable is quite large, so I'd like to whittle it down if possible.
One obvious way of doing this is to exclude unneeded matplotlib backends. I've tried running my script with python setup.py py2app --matplotlib-backends - which should compile only backends that are used in the script, as documented here: https://pythonhosted.org/py2app/options.html. The resulting executable is indeed a lot smaller, but it's broken. I also tried python setup.py py2app --matplotlib-backends "WXAgg" which failed the same way. Here is most of the traceback (awkwardly copied from Console, sorry).
import wx
File "wx/__init__.pyc", line 45, in <module>
File "wx/_core.pyc", line 4, in <module>
File "wx/_core_.pyc", line 14, in <module>
File "wx/_core_.pyc", line 10, in __load
ImportError: dlopen(/Users/***/***/***/dist/magic_gui.app/Contents/Resources/lib/python2.7/lib-dynload/wx/_core_.so, 2): Library not loaded: #rpath/lib/libwx_osx_cocoau-3.0.dylib
Referenced from: /Users/***/***/***/dist/magic_gui.app/Contents/Resources/lib/python2.7/lib-dynload/wx/_core_.so
Reason: image not found
Maybe I can explicitly tell it to include libwx_osx_cocoau-3.0.dylib. Or, maybe I need to explicitly include another backend (although I am using wxPython, so the WXAgg backend should be right).
I have two questions: first, is there a way I can include only required matplotlib backends without breaking my program? Second, are there other ways I could/should consider to make my program smaller with py2app?
I hope someone can help me as I've already spent several hours trying to sort this issue out without success. I am trying to use compileUi from the modPyQt4.uic to compile a PyQT Designer ui file into a Python py file, but when I do I get errors saying the DLLs fail to load.
Investigating further I found that these errors occur because Python cannot find Core QT module. I get the following error when trying to import the Core Qt module into Maya 2011:
from PyQt4.QtCore import *
# Error: line 1: DLL load failed: The specified procedure could not be found.
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# ImportError: DLL load failed: The specified procedure could not be found. #
I have seen that others have had similar issues and that the advice given in response is to to either move the DLLs /bin directory under PyQT4 into the root directory of the installation or alter the environment variable so that it points to the /bin directory ahead of all other directorys in the Python installation.
In my situation, however, the /bin directory doesn't even exist in my installation and even after reinstalling it it still is not there. Why is it not there? Have the developers moved the files elsewhere?
My installation is as follows:
Windows 7
Python 2.6.4 running in Maya 2011
PyQT v4.8.4 for Python 2.6
Once again I hope someone can help me as I want to lean PyQt, but if I can't solve this problem it is going to be an impassable barrier to progressing further.
Thanks in advance,
Terry Rozmus
Instead of writing " from PyQt4.QtCore import * "...use from PyQt4 import QtGui, QtCore..
I'm running Python 2.7, with the latest version of GTK installed.
I'm trying to import gtk with the following line of code:
import gtk
It is throwing the following error:
Traceback (most recent call last): File
"C:\GTKTutorial\tutorial.py", line 3, in
import gtk File
"C:\Python27\lib\site-packages\gtk-2.0\gtk__init__.py", line 40, in
from gtk import _gtk ImportError: DLL load failed: The specified
procedure could not be found.
How do I fix this? import pygtk is working, and I have Glade 3.8.0 installed.
Where did you get the PyGTK installer from? Try using this one: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.22/pygtk-all-in-one-2.22.6.win32-py2.7.msi
I just spent 3 days debugging this issue on my computer. This problem can have many root causes because importing gtk actually causes a lot of DLLs being loaded. If any of them fails, you get the same error message. For me, the break-through was
http://www.dependencywalker.com/
which I used to profile the command
python -i -c "import gtk"
On my PC, a wrong version of zlib1.dll was in the system32 directory, which prevented the right one in gtk\bin from loading. And it did that even though the first entry in my path pointed to gtk\bin.
I deleted the zlib1.dll from system32 (the application that put it there deserves to die) and the import worked fine. Your problem may be different, but dependency walker probably can give you a hint on what is going wrong.
Windows can have other reasons for loading a DLL other than the one you put in your directory or path. I found the blog
http://www.davidlenihan.com/2007/07/winsxs.html
useful. It describes Microsoft's solution for managing many versions of DLLs, and how to troubleshoot problems with it.