How to create .EXE file in python using cx_freeze - python-3.x

I have one application developed in python 3.2, which has inbuilt modules(ex: Tkinter, matplotlib, openpyxl), user defined modules & classes(ex: draw_graph, generate_report), icon files, log file, .csv, .docx etc. I am running this application from script(ex: testapplication.py)
I have setup file as
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script=r"C:\Python32\testapplication.py",
base="Win32GUI",
)
setup(
name = "TESTApp",
version = "0.1",
description = "An example",
executables = [exe]
)
Now I want to create a exe file of this application. can anyone please suggest me a way to do this?

So this is what you need to do. For starters, change script=r"C:\Python32\testapplication.py" to script=r"testapplication.py"
Then, put ALL the files to need to convert into C/python32 including the setup file. Then what you wan to do is get your command line up, and type the following commands: (assuming that you're cx_freeze file is named setup.py):
cd
cd python32
python setup.py build
And then you should have a build folder in that directory containing the exe file.

Related

Unable to add an icon to my progam build by py2exe

I've got a small program named "taquin" and I want to add an icon to the executable file.
My icon file is a image file 32x32 pixels extracted from a windows dll.
This program is built by py2exe with this small code
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [
{
"script" : 'taquin.py',
"icon_ressources" : [(1, "taquin.ico")],
}
],
)
Could you help me please ? My operating system is Windows 10...
All the code is here : draft.ericberthomier.fr/taquin.zip
There is a program called auto-py-to-exe which creates an exe out of your program without requiring you to create a setup file. The interface is great and allows you to easily create and exe without creating a setup.py. This also allows you to package your app as a single exe, without any other files. Below is a screenshot:
You can install the program by typing into the command line:
python -m pip install auto-py-to-exe
You can run it by typing in:
auto-py-to-exe
To see more about auto-py-to-exe, please visit the PyPI page at https://pypi.org/project/auto-py-to-exe/.

No module named 'tkinter' when trying to create exe file

I wrote some files in python and want to create an exe file. To do it with cx_freeze I create a setup.py file like that:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["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 = "LSR",
version = "0.1",
description = "",
options = {"build_exe": build_exe_options},
executables = [Executable("LS-R.py", base = base)])
then I write in the cmd :
python setup.py build
and I get this error:
error during GetDependentFiles() of "c:\users\appdata\local\programs\python\python36\dlls\tk86t.dll": (0, 'The system cannot find the file specified', 'c:\users\appdata\local\programs\python\python36\dlls\tk86t.dll', 2, None)
copying C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pywin32_system32\pywintypes36.dll -> build\exe.win-amd64-3.6\lib\pywintypes36.dll
copying C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pywin32_system32\pythoncom36.dll -> build\exe.win-amd64-3.6\lib\pythoncom36.dll
exe file created , but when I try open it I get this message :
ModuleNotFoundError:No module named 'tkinter'
someone know what is the problem? and what should I do to fix it? (I'm working in Windows OS)
Its Quite simple use;
pip install auto-py-to-exe
It will give you A GUI and is as simple as it gets. It is based on
Pyinstaller, cx-freeze, etc
See PyPI.
I was having the same problems even in Pyinstaller but this is the easiest way without any errors and is the most Effective way.
After Installation in cmd type
auto-py-to-exe
This will open a new Browser window with a beautiful and easy to use GUI.
It works for Tkinter well as I have used to to create like 50 Tkinter .exe files.
I made a program for activating windows in Tkinter with this;
See: https://drive.google.com/file/d/1RKLIlGcrra1pC5MyaPWrlQa1tW25Wc_q/view
I hope this makes your job quite easy.

how to fix .exe file , which is created using cx_freeze by converting .py to .exe

I have converted one .py file to .exe. The exe file created by this, is not working , it is closing automatically. In that application, I am supposed to take take two inputs. But screen is not staying.
I am using python 3.6 version. I have used cx_freeze library for this.
I have mentioned the code below which I used to create .exe for setup.py
Setup.py
from cx_Freeze import setup, Executable
setup(name = "html_guid_compare",
version = "1.0",
description = "Comparing two htm files for guid difference",
executables = [Executable(r"htm_guid_compare2.py")]
)
Input code:
path1 = input("Enter the First folder path:")
path2 = input("Enter the second folder path:")
when clicked on .exe file. It is not showing the screen, the screen is terminated.

How to change .py to .exe

I made a program in python which is in .py format. However, I would like it to be in .exe
The options I have found are:
py2exe
pyinstaller
The problems with those 2 are because I am running python 3.6 and those 2 programs do not support it, HELP!
Python 3.6 still isn't supported by Pyinstaller. So in order to use it you're gonna need Python 3.5 or below. So, you might wanna change your python version to 3.4 or 2.7. Then you can follow the procedure for creating the exe with pyinstaller. Also I think pyinstaller is a better option than py2exe.
However to make things work without switching to other versions, you might wanna try using cx_freeze:
1.Install the latest version of cx_freeze by pip install cx_Freeze.
2.Create a new python file named ‘setup.py’ on the current directory of your script.
3.On the setup.py, code this and save it:(here my prog.py refers to your .py file name)
from cx_Freeze import setup, Executable
base = None
executables = [Executable("my prog.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "<any name>",
options = options,
version = "<any number>",
description = '<any description>',
executables = executables
)
4.With shift pressed right click on the same directory to open a command prompt window.
5.Type: python setup.py build.
6.Check the newly created folder ‘build‘. Within that folder you can able to find your application.
pyinstaller
pip install pyinstaller
Basic usage is very simple, just run it against your main script:
pyinstaller /path/to/yourscript.py
cx_Freeze
pip install cx-Freeze
auto-py-to-exe
pip install auto-py-to-exe
Then to run it, execute the following in the terminal:
auto-py-to-exe
With a simple google search, I found this question which gives a link to a version of py2exe which happens to support python 3.3 and up. Here is the link!
On that page you will find the following bit of information:
Py2exe is a distutils extension which allows to build standalone Windows executable programs (32-bit and 64-bit) from Python scripts; Python 3.3 and later are supported. It can build console executables, windows (GUI) executables, windows services, and DLL/EXE COM servers.
Notice:
Python 3.3 and later are supported.
I have created a batch file to do the work, but first, go to https://datatofish.com/add-python-to-windows-path/ and add python to your path.
Then create a new notepad file with this:
SET /P _input1= Enter the file directory:
cd %_input1%
SET /P _input2= Enter the file name:
pyinstaller --onefile %_input2%
ECHO The exe file is in the dict folder in %_input1%
pause
Save this as a .bat file anywhere and run it.
Enter the directory of the python script.
then the name.
Hope this helps!

Error occurred when run program packed by py2exe

I packed a python program (involving PyQT4) with py2exe, the exe file run normally on my machine, but when i copy it to another machine, error occurred like following (in log file):
File "PyQt4\QtGui.pyc", line 12, in
File "PyQt4\QtGui.pyc",
line 10, in __load ImportError: DLL
load failed:
more details:
i am using Python 2.5.
MSVCR71.dll is available in the same directorywith the exe file.
my setup.py script:
# coding: utf-8
from distutils.core import setup
import py2exe
import sys
#this allows to run it with a simple double click.
sys.argv.append('py2exe')
script = [{
"script":"test.py",
'icon_resources':[(0, 'main.ico'),]
}]
py2exe_options = {
"includes":["sip",],
"dll_excludes": ["MSVCP90.dll",]
}
setup(windows=script, options={'py2exe':py2exe_options})
You need to distribute the pyqt4 dlls with your exe for it to run on computers where pyqt4 is not installed. You should be able to find the dlls in something like C:\Python27\Lib\site-packages\PyQt4\bin
To package the dlls with your exe you can use an installer like nsis or inno.

Resources