I'm trying to compile my python scripts using cx_Freeze, here is my setup file:
import cx_Freeze
import sys
import matplotlib
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r'C:\\Python35\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\\Python35\\tcl\\tk8.6'
executables = [cx_Freeze.Executable("HomeScreen.py", base=base,
icon="icon.png")]
cx_Freeze.setup(
name = "LeagueBoost",
options = {"build_exe":{"packages": ["sqlite3","requests","time","sys","os","statistics","matplotlib","random","collections"],
"include_files": ["Assets", "LeagueBoost_v1.py","LBRun.py","graphSetup.py","profilepage.py","Assets_rc.py"]}},
version = "1",
executables = executables
)
But when I give the cmd command C:/python35/python.exe, it gets to copying C:\python35\python35.dll -> build\exe.win-amd64-3.5\python35.dll it pops up "python has stopped working"
This is crazy
after hitting my head against the wall for the weird reason python crashes when I tried to build executable with cx_Freeze,
what solved my problem is using ico format for icon file.
Your icon file should be icon type not png, may be because png is not supported by cx_Freeze.
In your setup.py change
icon="icon.png" to icon="icon.ico",
please note the icon file must be in ico format, don't act smart and just change the extension.
If it still doesn't work you can give it a trial without writing this option at all icon="icon.png" and see if it works.
Related
I wrote a program in Python and created an executable with cx-Freeze. I had to include tk and tcl libraries, as well as some images, in the setup.py for the executable to run correctly.
I linked these files to absolute paths on my computer, thinking that cx-freeze would copy these files over to the final executable folder so that it would become a part of its own package.
The program runs perfectly on my PC, but does not run on my colleague's PC.
Including the tcl and tk libraries as well as the images was a part of my troubleshooting process when the .exe wouldn't run. I have no idea of what to do next.
'''This is my setup.py file.'''
from cx_Freeze import setup, Executable
import sys
import os
includes = []
include_files =
[r"C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\DLLs\tcl86t.dll",
r"C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\DLLs\tk86t.dll",
r"C:\Users\jchoujaa\Desktop\Code\STARx App\Savvy Logger\Developer\Imaging\savron.png",
r"C:\Users\jchoujaa\Desktop\Code\STARx App\Savvy Logger\Developer\Imaging\s-icon.ico",
r"C:\Users\jchoujaa\Desktop\Code\STARx App\Savvy Logger\Developer\Imaging\STAR.png"]
os.environ['TCL_LIBRARY'] = r'C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\jchoujaa\AppData\Local\Programs\Python\Python37\tcl\tk8.6'
base = 'Win32GUI' if sys.platform == 'win32' else None
setup(name = "SavvyLogger",
version = "1.0",
description = "Logger Interpreter",
options={"build_exe": {"includes": includes, "include_files": include_files, 'packages': ['pandas', 'numpy']}},
executables = [Executable("SavvyLogger.py", base=base)])
This is the error my colleague receives when attempting to open my executable:
enter image description here
Henry Yik's suggestion in the comments worked.
The problem was that I had set the path of the images used by tkinter to a folder located on my desktop.
Henry suggested I place the image files in the same folder as my .py script and remove the path names from the image variables.
This worked!
I've been dealing with this for days now and hope to find some help. I developed a GUI-application with imported modules tkinter, numpy, scipy, matplotlib, which runs fine in python itself. After having converted to an exe everything works as expected, but NOT the matplotlib section. When I press my defined plot button, the exe simply closes and doesn't show any plots.
So I thought to make a minimal example, where I simply plot a sin-function and I'm facing the same issue:
Works perfect in python, when converting it to an exe it crashes when pressing the plot button. Here is the minimal example:
import tkinter as tk
import matplotlib.pyplot as plt
import numpy as np
class MainWindow(tk.Frame):
def __init__(self):
tk.Frame.__init__(self,bg='#9C9C9C',relief="flat", bd=10)
self.place(width=x,height=y)
self.create_widgets()
def function(self):
datax = np.arange(-50,50,0.1)
datay = np.sin(datax)
plt.plot(datax,datay)
plt.show()
def create_widgets(self):
plot = tk.Button(self, text='PLOT', command=self.function)
plot.pack()
x,y=120,300
root=tk.Tk()
root.geometry(str(x)+"x"+str(y))
app = MainWindow()
app.mainloop()
And here is my corresponding setup.py for converting with cx_Freeze:
import cx_Freeze
import matplotlib
import sys
import numpy
import tkinter
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("test.py", base=base)]
build_exe_options = {"includes": ["matplotlib.backends.backend_tkagg","matplotlib.pyplot",
"tkinter.filedialog","numpy"],
"include_files":[(matplotlib.get_data_path(), "mpl-data")],
"excludes":[],
}
cx_Freeze.setup(
name = "test it",
options = {"build_exe": build_exe_options},
version = "1.0",
description = "I test it",
executables = executables)
Any ideas that might solve the issue are highly appreciated. I'm working on a 64-bit Windows10 machine and I'm using the WinPython Distribution with Python 3.4.3.
I found a potential solution (or at least an explanation) for this problem while testing PyInstaller with the same test.py. I received error message about a dll file being missing, that file being mkl_intel_thread.dll.
I searched for that file and it was found inside numpy folder.
I copied files matching mkl_*.dll and also libiomp5md.dll to the same directory where the test.exe created by python setup.py build was. After this the minimal test.exe showed the matplotlib window when pressing the plot button.
The files were located in folder lib\site-packages\numpy\core.
I really wanted to post this as a comment, but I don't have the reputation. This is mostly a followup to J.J. Hakala's answer about how to find the cause.
If one changes the base to "Console", i.e. using
base = "Console"
rather than
base = "Win32GUI"
a console will also pop up when the program starts and this error is printed
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Which can help finding the cause of the problem pretty faster.
I thought this would be worth mentioning, since this trick can also be helpful to diagnose other problems. In the final release, one can revert back to Win32GUI to avoid the extra console. I should give the credits to this other stackoverflow post
I have followed #J.J. Hakala's answer, but I found that it's not necessary copy all mkl_*.dll and libiomp5md.dll files. For me it worked with libiomp5md.dll mkl_core.dll mkl_def.dll mkl_intel_thread.dll. This helps to reduce the final bundle size in ~500MB.
Also, you can include the files you want to copy in the include_files option. You also could only want to include them if sys.platform is win32.
I'm using Anaconda as well as #Matt Williams, so, changing a bit the OP's code:
import cx_Freeze
import matplotlib
import sys
import numpy
import tkinter
import os
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
build_exe_options = {"includes": ["matplotlib.backends.backend_tkagg","matplotlib.pyplot",
"tkinter.filedialog","numpy"],
"include_files":[(matplotlib.get_data_path(), "mpl-data")],
"excludes":[],
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
DLLS_FOLDER = os.path.join(PYTHON_INSTALL_DIR, 'Library', 'bin')
dependencies = ['libiomp5md.dll', 'mkl_core.dll', 'mkl_def.dll', 'mkl_intel_thread.dll']
for dependency in dependencies:
build_exe_options['include_files'].append(os.path.join(DLLS_FOLDER, dependency))
executables = [cx_Freeze.Executable("test.py", base=base)]
cx_Freeze.setup(
name = "test it",
options = {"build_exe": build_exe_options},
version = "1.0",
description = "I test it",
executables = executables)
Check if you have numpy+mkl package installed. Uninstalling numpy and installing numpy+mkl package solved my issue of getting error related to mkl_intel_thread.dll
I made a tkinter app on my mac which runs well, when I run it from the terminal. Now, I want to make an executable version of it, but I get this error message after python setup.py build:
error: [Errno 2] No such file or directory: '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl'
setup.py:
import cx_Freeze, sys
import os
import os
os.environ['TCL_LIBRARY'] = "/System/Library/tcl/8.4"
base = None
if sys.platform == 'Win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("multiframe.py", base=base)]
cx_Freeze.setup(
name="cu",
options = {"build_exe": {"packages":["tkinter"]}},
version= "0.01",
description = "dasdasd",
executables = executables
)
I know that something is wrong with the tcl import but I have tcl in Python3.6 folder on windows but I don't in mac
In your options statement, you tell the system to import the "tkinter" package. "tkinter" is Python 3. "Tkinter" is for Python 2. If you are running Python 2 on your Mac, you need to use "Tkinter" instead of "tkinter" for a package. And, of course, you'll need to make sure your "cu" app runs on Python 2.
Also, the line
os.environ['TCL_LIBRARY'] = "/System/Library/tcl/8.4"
points to an old version of Tcl. Probably doesn't matter. But the later Python 2.7 and Python 3 both come with 8.5. You should probably upgrade your Mac to Python 3 to be the same as your Windows machine, so that your code will run in both places. Otherwise you may need little tweaks in your code to get the same code to run on both.
I have a simple application made in python3, I only have one window and a button, try it with the bdist command:
python setup.py bdist --format=zip
but not working for me.
with: cx_Freeze
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# 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 = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("text.py", base=base)])
Have any suggestions or recommendations?
a folder is created but I dont see the .exe
If I use images where should I put it?
What about the modules?
What happens if I use relative paths?
Have you tired PyInstaller?
PyInstaller supports cross-compilation:
Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.
More information here
Hope this helps :)
I have a python script that I'd like to freeze. I made the cx_freeze script, and ran it. The .exe works well, but in the frozen script I open a .html file. When the file opens the webbrowser gives me the error "File not found: Firefox cannot find the file at /c:/blah/blah/blah/somefile.html"
As I understand it, this is because cx_freeze is confusing my OS between linux and Windows. However, I'm not sure this is it because I have the code
if sys.platform == "win32":
base = "Win32GUI"
In my setup file. Does anyone know what's going on?
My entire setup file is
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# 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 = "someexe",
version = "0.1",
description = "someexe description",
options = {"build_exe": build_exe_options},
executables = [Executable("someexe.py", base=base)])
copied from the cx_freeze distutils page and edited to fit my needs.
Instead of using os.chdir('C:/path/to/dir'), you should be using os.chdir('C:\path\to\dir'). It's an error in your script, not your cx_freeze setup file.