Writing out document in GUI executable using cx_freeze not working - user-interface

I made an executable gui (with tkinter) file using cx_freeze. The executable has several buttons. When the user click the button, the calculation should work and then it will write out an xlsx file.
Everything went good when I make the executable, there was no error. But when I click the button, it seems like the calculation works (since it was loading), but then it does not write out the xlsx file.
I don't know what went wrong. Anyone can help me?
Here's the setup.py file:
import sys
from cx_Freeze import setup, Executable
import os
import tkinter
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [Executable("gui.py", base=base)]
packages = ["tkinter", 'xlsxwriter', 'matplotlib']
options = {
'build_exe': {
'includes': ["os", "tkinter", 'numpy.core._methods', 'numpy.lib.format', 'xlrd', 'scipy', 'pandas'],
'include_files': [r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
r"C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll"]
},
}
os.environ['TCL_LIBRARY'] = r'C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name="Tool",
version="1.0",
description="Tool prototype for calculating",
options=options,
executables=executables
)

I've solved the problem.
What i did was to change the base in setup.py to : base = None
and I installed the xlsxwriter by following this thread: ImportError: No module named 'xlsxwriter': Error in bamboo
After this, I encountered another problem:
No module named: scipy.sparse.csgraph._validation
but I simply add this to the 'includes': ['scipy.sparse.csgraph._validation', ...]
now everything works perfectly.
I hope this helps anyone who has the same problem.

Related

How to use askopenfilename for .exe files?

I have a program with a GUI where you can search for Files.
I use the askopenfilename from Tkinter.
root = Tk()
root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
After I built it into a .exe file with pyinstaller, I wanted to start it.
But if I start the .exe file, I see a window for a short while and then it closes instantly.
It helped not to use root.mainloop.
What can I do?
Thanks
Your problem is most likely an issue in the imports, you didn't include any so all I can do is assume.
This is what I usually would use:
(Tested working on python 3.8.1 x64, pyinstaller 3.6)
from tkinter import *
from tkinter import filedialog
root = Tk()
root.withdraw()
root.filename = filedialog.askopenfilename(initialdir = "/",
title = "Select file",
filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
Made the .exe with pyinstaller.exe --onefile "path/to/script.py"

Quit cmd while exe is running

I have a .exe (PyQt5 + python3), the issue is that when I start the application, the cmd window is always initialized in the background.
I want that the cmd window is not initialized.
This is the code that I used to convert to .exe:
import cx_Freeze
from cx_Freeze import *
setup(
name = "interfaz",
options = {'build_exe': {'packages': ['cv2', 'numpy']}},
executables=[
Executable(
"interfaz.py",
)
]
)
This is an image showing the app:
According to the cx_Freeze documentation, in order to avoid that the command prompt appears briefly under Windows, you need to:
Freeze your application with the Win32GUI base [...]. This doesn’t use a console window, and reports errors in a dialog box.
Try thus to modify your setup script as follows:
import sys
from cx_Freeze import setup, Executable
# GUI applications require a different base on Windows (the default is for a console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="interfaz",
options={'build_exe': {'packages': ['cv2', 'numpy']}},
executables=[Executable("interfaz.py", base=base)])

GUI module not found

I'm trying to run the following code:
# To use interactive plots (mouse clicks, zooming, panning) we use the nbagg back end. We want our graphs
# to be embedded in the notebook, inline mode, this combination is defined by the magic "%matplotlib notebook".
%matplotlib notebook
import SimpleITK as sitk
%run update_path_to_download_script
from downloaddata import fetch_data as fdata
import gui
# Using an external viewer (ITK-SNAP or 3D Slicer) we identified a visually appealing window-level setting
T1_WINDOW_LEVEL = (1050,500)
When I run it in spider 3.2.6 I get:
ModuleNotFoundError: No module named 'gui'
Any help would be appreciated.
Code source: http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/30_Segmentation_Region_Growing.html
This isn't a spyder issue.
The gui module is part of the notebooks repository. Either clone the repository or just download this file. Same goes for the downloaddata module.

.exe doesn't launch after making it with py2exe

So I have been working for 2 months on a project in python (it is the first time I'm using python).
The project is basically:
- 1 main file,
- 1 GUI file using PyQt4
- and a few classes for the calculation functions.
Here is my setup.py file:
from distutils.core import setup
import py2exe
from glob import glob
import matplotlib
dataf = [
(r'mpl-data',
[r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\stylelib',
glob(r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\stylelib\*.*')),
(r'mpl-data\images',
glob(r'C:\Python27\Lib\site-packages\matplotlib-1.4.3-py2.7-win32.egg\matplotlib\mpl-data\images\*.*')),
(r'mpl-data\fonts',
glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts\*.*')),
(r'Qt\imageformats',
glob(r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\*.*')),
(r'Resource',
glob(r'C:\PythonWS\Lince5M\*.png')),
]
includes = ['sip', 'PyQt4.QtCore', 'PyQt4.Qt', 'PyQt4.QtGui', 'PyQt4.QtNetwork',]
pack = ['numpy.core', 'matplotlib.backends', 'matplotlib.axes', 'zmq', 'PyQt4.QtCore', 'PyQt4.Qt',
'PyQt4.QtGui', 'PyQt4.QtNetwork', 'CaptureImage', 'ClusterDetectionIterative', 'DisplayPanel',
'ImageProcessAvg', 'WriteOutputFiles',
]
excludes = ['_gtkagg', '_agg2', '_cairo', '_cocoaagg', '_fltkagg', '_gtk', '_gtkcairo', '_thread',
'_macosx',
]
#I admit not understand really much those excludes, that's why I don't put them in the setup
opts={
'py2exe': {
'compressed': 2,
'optimize': 2,
'includes':includes,
'packages':pack,
#'excludes':excludes,
'bundle_files': 1,
}
}
win = [{
'script': 'Application.py',
'icon_resourses': [(1,'icone\icone.png')]
}
]
setup(
version = "0.1",
console=win,
options=opts,
data_files=dataf,
)
My programs works fine when launched with Eclipse.
The making of the executable seems to be done fine too, except for the list of missing modules there is no error, and my .exe is created...
But when I start it nothing happens... I have been looking for a few days now and I really have no idea on what is wrong since nothing gives me a notice on the problem..
If it could be of any use, my project uses those imports:
PyQt4, os, decimal, time, numpy, sys, clr, matplotlib, cv2, and a dll we made in the company.
So here is my question:
Anyone ever got this kind of error?
Does any one know how to get an output, or anything that could tell me where is the problem?
There should be a [.exe name].log file in the "dist" folder that py2exe created.
Try looking to see if that can glean some information on your problem.

Issue with GTK and D

OK, so I'm trying to experiment a bit with D and Gtk.
On OSX, I download the sources and did the typical make, sudo make install.
Now the Gtk sources are installed here :
/usr/local/include/d/gktd-2
However, when I'm trying to build one of the demos included (e.g. /demos/gtk/HelloWorld.d), with :
dmd -I/usr/local/include/d/gktd-2 HelloWorld.d
The compiler still complains :
HelloWorld.d(24): Error: module MainWindow is in file 'gtk/MainWindow.d' which cannot be read
import path[0] = /usr/local/include/d/gktd-2
import path[1] = /usr/share/dmd/src/phobos
import path[2] = /usr/share/dmd/src/druntime/import
What am I missing?
UPDATE :
I think I got it to work, but it's one of those cases where I simply don't know how that happened... lol
To me it seems like a typo - /usr/local/include/d/gktd-2 seems incorrect. It should be something like /usr/local/include/d/gtkd-2 . Following should work: dmd -I/usr/local/include/d/gtkd-2 HelloWorld.d (note the change from "gktd" to "gtkd").

Resources