Using cx_Freeze to Make First Program Into exe File - python

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.

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.

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...

Make executable a python file [duplicate]

I am trying to compile a hello world program in Python into a stand-alone binary/package on Linux using cx_Freeze. When cx_Freeze is run, it completes without an error but when I attempt to run the generated executable, I am given the error:
ImportError: No module named __startup__
My setup.py file is:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
base = 'Console'
executables = [
Executable('test.py', base=base)
]
setup(name='test',
version = '1.0',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)
And it is run as such:
python setup.py build
I am confused as to why this is happening. If the ImportError was for a library, I would understand - but __startup__ is unfamiliar to me.
Thanks.
I had the same problem with cx_Freeze 5.0.0. I was able to fix this after downgrading cx_freeze to 4.3.4. Other versions may also work.
I encountered the same problem.For your goals, you can try pinstaller.'hello world' accurately compile. But the question remains open, how to conquer this bug

cx_Freeze : DLL load error with tkinter

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.

What is my next step using cx_Freeze?

Ok so I have python 3.2 installed and I have cx_Freexe 4.2.3 installed.
I have a folder called Python stuff. In this folder there are 2 files.
setup.py and holg.py (my application)
Here is my setup.py:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "holgame",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("holg.py", base=base)])
The next step I have been doing is Run > cmd:
python setup.py build
what I get is:
'python' is not recognized as an internal or external command, operable program or batch file.
I am only a beginner so I need clear steps. Maybe my programs should be in a different folder or something, I can't really be sure. Does anyone know what the problem is? Thanks
You either need to put Python on the Windows path, or you need to use an explicit path to python. Try:
$ \Python32\Python setup.py build
Here are some good instructions for getting Python installed on your Windows machine: https://openhatch.org/wiki/Boston_Python_Workshop_5/Friday/Windows_set_up_Python
You will first need to cd to the directory containing your code and setup.py. You should find a Windows command prompt tutorial to help with some of this basic stuff.

Categories