I have been building an application on Linux using python pygobject, and now I need to distribute it on Windows.
I first installed pygobject via msys2 (as per the official pygobject documentation)
Now, using msys2/mingw32, I can run my program typing
python3 main.py
But when I try to freeze it into a .exe with Pyinstaller, and try to run the produced .exe
If I Don't use --onefile, I get an import error on the _struct module (whereas "import _struct" works in python shell)
If I use --onefile, I get the Following error :
error:
lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-ani.dll could not be extracted!
fopen: No such file or directory
I’m using the devel version of Pyinstaller. I know next to nothing on Windows OS… does anyone know how to fix that error ?
It sounds like you were on the right path, unfortunately you ran in to a bug in PyInstaller. The good news is that the issue with the No module named '_struct' error is now fixed and released in version 3.6 and later. I would recommend using the --onedir mode of PyInstaller, you should be able to successfully package a GTK app for Windows.
Related
As you can see I have imported the modules correctly using pip install. I googled a bit why the module was not imported and I realized I have to add it to PATH. I did that too but now there is a new error something about a syntax error
File "pygame/__init__.py",
self.reason = f"{exc_type.__name__}: {self.info}"
Is this because my chrome book can not run Pygame or is the problem something else?
Picture of my terminal with the error:
you need to run python3. to start python 3. Just running python starts python 2.7.
you have your installed packages in python 3.9 version while your python environment is 2.7, look for python3 executable and try with that version
I recently installed the opencv package using pip install and I wrote a small code to test it (cvtest.py). The code runs through the python idle shell but running it though the command prompt gives the error
Error while finding module specification for 'cvtest.py' (ModuleNotFoundError: __path__ attribute not found on 'cvtest' while trying to find 'cvtest.py')
I tried uninstalling and reinstalling both python and the package. looking up the system path using python -m site gives these results. I am the only user of my laptop.
sys.path = [
'C:\\Users\\Kareem Mostafa\\Desktop\\Assignments\\computer vision',
'G:\\Python37\\python37.zip',
'G:\\Python37\\DLLs',
'G:\\Python37\\lib',
'G:\\Python37',
'G:\\Python37\\lib\\site-packages',
This is the code I am using
import cv2
x=cv2.imread('backpack for sale.jpg',0)
cv2.imshow('x',x)
update: the problem is happening with all the py files I am having whether they require imports or not. apparently python is looking for _init_.py for all the files as if they are packages. Any idea what is going on?
For anyone else that had this problem (assuming kareemostafa has fixed it now!)
Removing the .py suffix on the python -m command fixes this problem, it appears -m only requires module names whereas running it directly as a python file (no -m option) requires the .py suffix
In your case python -m cvtest should be sufficient.
So I'm trying to fix up an old program and I've been trying to run its main script on my Mac, but it says it can't find module gtk (it says it's a required dependency in the README). I have tried a ton of things to get this script to run, I've installed both python 2 and 3 with brew, installed many versions of pygtk with brew, tried to run the script on my user dir and in a python 2 and 3 virtualenv, added #!/usr/bin/env python2 and added a sys path to where brew installed pygtk, but all to no avail. Neither gtk nor pygtk can seem to be found. My original attempt at using pip to install pygtk resulted in this output:
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/6l/k1kfh5415ln0886zznkffpr80000gn/T/pip-install-
50TCjw/pygtk/
So... my question is: how should I proceed? I'm actually not sure what gtk does. Should I attempt to update this program to python3 compatibility? What is the state of compatibility for gtk? And how can I check if I actually even have gtk on my system? Because homebrew is pretty convinced that I do.
Update:
So I manually used the python2.7 that was installed via brew (in usr/local/Cellar/python#2) and this seemed to fix the gtk problem. However now it can't import webkit module which is somewhere else in the program, and I'm stuck here now...
Finally got all the dependancies loaded. python-webkit was apparently completely deprecated, I had to find the last macOS compatible version of it at https://code.google.com/archive/p/pywebkitgtk/downloads and then it was a simple matter of running its configure file and adding its install location to my Cellar python#2 program's sys path. Now the rest of the program is pretty messed up but I accomplished what I wanted for now
Is there now an easy protocol to build a .exe from python 3.5+, using modules pyqtgraph, qt5, theano, pymc3, numpy, scipy, os and sys, and opening a simple GUI stored in a '.ui' file ? I lost hours and eventually failed to make one (for w7-64 bits). Help !
preliminary failure with py2exe: I first install py2exe for python 3 but it turns out this is not compatible with my python 3.6 yet, so I downgraded to python 3.5… to get a bunch of errors. Then I went to forums and tried the proposed cures but failed (I’m uneasy with windows), the alternative being to downgrade to python 3.4… So I downgraded to python 3.4 to get an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums but by default I don’t have the permission to modify system directories… When I eventually had this permission it turns out the ‘regsvr32’ command fails (isn’t this for 32 bits ? but there is no ‘regsvr64’…). Following episodes are described below.
update august 23, 2017, 1pm:
I also tried pyinstaller as advised but it failed (see my related question build a .exe for Windows from a python 3 script importing theano with pyinstaller)
I also tried cx_freeze but it failed (see my related question build a .exe for Windows from a python 3 script)
I also tried pynsist but it fails (same link than above)
what's next ?
update september, 2, 2pm:
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
see build a .exe for Windows from a python 3 script importing theano with pyinstaller
Pyinstaller Works with Python 3.5 and it is working even for packages like tensor-flow, scipy , etc (The packages I worked with)
py -3.5 pip install pyinstaller
then go the C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts
and run the command
pyinstaller <code .py file along with directory> --onefile
--onefile : is for compressing the build and get a single file as output
I would suggest pyinstaller see http://www.pyinstaller.org/
The pyinstaller already supports 3.5
The development version supports 3.6
It is better to use spec file to import other hidden libraries. I listed all Sklearn libraries and add them to spec file as a hiddenimports, you can add libraries you used in your project.
I'm trying to get an example of PyMoskito running under Python 3.5.2 Win7 64 bit
This library needs PyQt4 which in turn needs SIP.
1- I installed SIP using pip3 install SIP which ended up successfully (with a notice to update my pip).
2- I even barely know Python. So I tried installing PyQt4 with a binary executable. The binaries provided at riverbankcomputing.com/software/pyqt/download are for python 3.4 so I downloaded an unofficial wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4 with a name PyQt4-4.11.4-cp35-none-win_amd64.whl. Then I cd'ed into the respective directory and installed it with pip which ended up successfully.
Now, I don't know what is the standard procedure for testing if a library is working. So I ran setup.py from the main directory of library and I assumed it set things up. Then I ran an example from examples folder and I get this error
Traceback (most recent call last):
File "C:\Users\****\Documents\Python Libraries\pymoskito-master\pymoskito-master\examples\ballbeam\main.py", line 3, in <module>
from PyQt4 import QtGui, QtCore
ImportError: DLL load failed: The specified module could not be found.
I assume python could NOT find the PyQt4 dependencies. I searched stackoverflow and non of the solutions worked. Here is what I tried so far:
There is NO /bin directory in C:\Python35\Lib\site-packages\PyQt4. So all dlls are already in the \PyQt4 directory
I added this directory to System PATH env. var. Same error occurs
I appended this directory to sys.path and tested it. Same error occurs
I created a \bin directory and copied all \PyQt4 into it. Then added it to PATH. Same error occurs
After that, I installed python 2.7 and PyQt4 from riverbankcomputing but not SIP. I still have the same problem
I really don't know what else should I do. I'm actually frustrated by all the mentioning of whether OP is using Python 2 or Python 3 or QT4 or QT5 or x86 or x64. I believe backward compatibility should be the minimum of a programming language and this is definitely a mess for Python
The short answer, I believe is that you have pyqt4 (a python interface to the qt4 library), sip (an automated c++-to-python communication library) but not qt4 itself (the UI library). qt4 is it's own monolithic c++ project with its own build and dependency problems.
You may be able to find the various pieces at http://www.lfd.uci.edu/~gohlke , but I would recommend installing the Anaconda distribution of python ( https://www.continuum.io/downloads ), which provides binary packages for things like qt4 and pyqtgraph, the former of which is installed by default, the latter requiring a command like
conda install pyqtgraph
After this, pip install of pymoskito should work.
There is also mention in the readme of vtk, but it is not in the requirememnts. vtk is also a monolithic c++ library and hard to build, but conda has that too, albeit not in the default channel for py35:
conda install vtk -c menpo