cx_Freeze : DLL load error with tkinter - python

I am currently trying to use cx_Freeze to create a .exe file for my python scripts.
First, do cx_freeze get all data on the folder into the build folder?
Secondly, I'm having an issue when launching the .exe file. The fact that the first file opens the second one could be the issue ?
The console opened and closed, according to another post on Stackoverflow, I created a .bat file containing :
myfilename.exe%1
pause
to check out what the issue is and I got this issue :
Issue
I've really no idea what to do next since I tried many things on the setup.py to make things working.
Here is the setup.py :
"""setup.py"""
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"
build_exe_options = {"includes": ["tkinter"]}
setup(name="todolist",
version="0.1",
description = "A simple to do list with differnt tabs per account.",
options = {"build_exe": build_exe_options},
executables = [Executable("login_system.py",base=None)])
I'm only using pillow as an external module but it doesn't seem to be the issue.
Thanks for your help by advance !
EDIT : I managed to fix it by adding the ddl missing files path inside the "include_files" option:
build_exe_options = {"packages": ["os", "tkinter"], "include_files": ["to_do_list.py","336sur525.gif","384sur540.gif",
"accounts.txt","button_hide_2.gif","button_quit_2.gif","choose.gif","icone.ico","user.gif",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll"]}
My script was using a subprocess.call function to call another script, so it didn't work after becoming .exe, I added the .py file inside the "include_files" and it worked as intended.

Related

How to convert .py file to .exe hiding the console (based on another stackoverflow's post)

I tried several ways to convert a .py file to a .exe, but it always gave me the same problem, namely that the .exe file didn’t work. I found a solution thanks to this post, but it is not specified how to hide the console. Could someone check the post and tell me how to do it?
EDIT:
After searching I found out a solution for my problem:
import cx_Freeze
exe = [cx_Freeze.Executable("game.py", base = "Win32GUI")] # "Win32GUI" -> no console
packages = ["os", "time", "random", "io", "pygame", "base64", "paho.mqtt"]
cx_Freeze.setup(
name = "ForzaQuattro",
version = "1.0",
options = {"build_exe": {"packages": packages,
"include_files": []}},
executables = exe
)
I used cx_Freeze with the param base="Win32GUI", this will hide the console of the exe file.
After that you will just replace game.py with the name of your python script, replace packages with the package that you need, save that file as setup.py and run by command prompt python setup.py build.
That will genarate a directory with all what you need.
pyinstaller -w [PathToYourFile]
The -w option hides the console.

cx-Freeze Executable Won't Run on Another Computer

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!

Build a .exe file from .py with SQLite database

Program makes appointments and places them into schedule which are written in QsQLite database. The program runs from .py but I need it to be in .exe.
I have used cx_Freeze to create an .exe file, but the program does not generate the SQLite database.
So here is my setup file:
from cx_Freeze import setup, Executable
import os
import sys
os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35\tcl\tk8.6'
build_exe_options = {"packages": [
'os','sys','sqlite3'], 'include_files': [os.path.join(sys.base_prefix, 'DLLs', 'sqlite3.dll'), 'main.py','util.py','data.db']}
setup(
name = "Eclients",
version = "0.1",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py")]
)
But database can't be opened
So,how it can be solved?
You are not including your SQLite database file in the include_files statement. See the documentation: http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files
A better solution, however, would be to provide an option to create the missing database file when needed. This would allow the database's SCHEMA be defined within your script, and be kept consistent with your programme logic. If it needs populating with data, this might however be a less optimal solution.
Solved this problem by copying the whole 'sqldrivers' folder from C:\Program Files\Python35\Lib\site-packages\PyQt5\pluginsto main.exe directory.

How to use cx_Freeze to make an executable python program

I downloaded cx_Freeze because I'm trying to make a .exe file to share with my platoon and I've been reading through the docs as well as scrolling through cx_Freeze tutorial. After following both of those I still don't know why this isn't working for me. I'm on Python 3.6.2 and I have the path directly setup to the command line.
I tried to launch with setup.py and Julian date 2.py on the desktop and I tried adding them to same folder, but no matter what I try I get back this error when I type python setup.py build, python: can't open file 'setup.py': [Error2] no such file or directory or file exsists. Below is my setup.py code.
from cx_Freeze import setup, Executable
setup(name = "Julian date 2" ,
version = "0.1" ,
description = "" ,
executables = [Executable("Julian date 2.py")])
Another issue I ran into was trying to type cxfreeze Julian date 2.py --target-dir dist I get the error 'cxfreeze' is not recognized as an internal or external command, operable program or batch file.
When you type python setup.py build, you are supposed to be in the directory with setup.py and not anywhere else. So use the command cd to get there.
cx_freeze is not in your path variable so cxfreeze Julian date 2.py --target-dir dist will not work and you have to instead add it to your path (somehow) [not recommended]
Hope this helped.
P.S.
executables = [Executable("Julian date 2.py")]) takes base too. If you want a console application:
executables = [Executable("Julian date 2.py",base='None')])
Gui for windows:
executables = [Executable("Julian date 2.py",base='Win32GUI')])
And you forgot your exe options in setup(). I recommend adapting the setup.py script on cx_freeze doxs:
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"
setup( name = "name",
version = "0.1",
description = " ",
options = {"build_exe": build_exe_options},
executables = [Executable("file.py", base=base)])
I solved the first issue, my file was named 'setup.py' and not just 'setup' as it's supposed to be...The name must be setup, the extension .py
Know it's DUMB, after hours, that was the problem...

Using cx_Freeze to Make First Program Into exe File

I made my first program (a gui calculator) in python using tkinter and am trying to use cx_freeze to turn it into an exe file. I'm really confused in how it works thought. I used cxfreeze quickstart in the scripts section of python33 to make my setup file. The program is named Calculator
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
executables = [
Executable('Calculator.py', 'Win32GUI')
]
setup(name='Calculator',
version = '1.0',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)
When I got to the console and type python setup.py build I get the error:
cx_Freeze.freezer.ConfigError: no initscript named Win32GUI
can anyone recommend a tutorial for using cx_Freeze or any other programs to make python code as exe format?
I suggest you try PyInstaller.
To convert a script to an exe file, you'd have to type something like this in a command prompt:
/path/to/python/pythonX.Y pyinstaller.py --onefile /path/to/your/script.py
Simple as that.

Categories