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
Related
I want to make a .exe file from my python project, I have made a GUI in tkinter. This project has multiple files and uses a variety of libraries.
I tried to use auto-py-to-exe but it gave a variety of errors concerning the use of tkinter, saying it can not find tkinter. I do not understand this error since tkinter is automatically installed with python? Are there better ways to use auto-py-to-exe or better programs to convert a hole project to .exe? I also tried pyinstaller, but when opening the program it immediately closes again. The program does run properly in pycharm.
The error is I\output\main_init_.py", line 1, in <module> import tkinter ModuleNotFoundError: No module named 'tkinter'
I personally use CX-Freeze to compile my executables. I have probably used it over 100 or so updates of my tools and typically the problem I run into is either related to missing file that need to be identified in the setup.py file or the fact that when it compiles the Tkinter folder it uses a capital T instead of a lower case t so after I compiling an app I have to manually update the folder to be lowercase T.
Here is an example of the setup file.
As you can see below when compiling tkinter you need to ID the TK and TCL library folders in order for it to compile the listed DLL files properly.
from cx_Freeze import setup, Executable
import os
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r'C:\Users\user\Desktop\Python381\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\user\Desktop\Python381\tcl\tk8.6'
build_exe_options = {'packages': ['os',
'json',
'http',
'email',
'pyodbc',
'openpyxl',
'calendar',
'threading',
'datetime',
'tkinter',
'tkinter.ttk',
'tkinter.messagebox'],
'excludes': ['PyQt5',
'PIL',
'numpy',
'pandas'], # 'urllib', # 'encodings', # 'numpy'
'include_files': [r'excel_temp.xlsx',
r'opt_3_excel_temp.xlsx',
r'tcoms_excel_temp.xlsx',
r'main_config.json',
r"C:\Users\user\Desktop\Python381\DLLs\tcl86t.dll",
r"C:\Users\user\Desktop\Python381\DLLs\tk86t.dll"]}
setup(
name='<GIT>',
options={'build_exe': build_exe_options},
version='0.57',
description='<GIT - Global Inventory Tool!>',
executables=[Executable(r'C:\Users\user\PycharmProjects\Py381_GIT\MAIN.py', base=base)]
)
After you run the compiler you will often get an error that looks like this.
The error NoduleNotFoundError: No module named 'tkinter' is due to the odd behavior of the compiler giving the tkinter folder a Capital T like the below image in the lib folder.
In this case you would update the library to be a lowercase t.
Use this package :
python -m pip install auto-py-to-exe
Run this command :
auto-py-to-exe
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...
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.
I'm having trouble creating an .exe file with cx_Freeze. I'm trying to use this Pygame game which needs some .png's, .gif's and .ogg's to run. I have tried to compile a simple Python only (no pygame or additional files) using the commmand line and a setup.py, but neither worked and I'm a bit out of my death.
I have installed cx_Freeze and checked it worked with ''import cx_freeze' in the IDLE not throwing an error. I'm using Python 3.3 on Windows 7 with the correct versions of pygame and cx_freeze for my python version.
Can anyone assist me in creating this .exe?
To include files in your .exe you should write a setup.py file that is similar to this:
from cx_Freeze import setup, Executable
exe=Executable(
script="file.py",
base="Win32Gui",
icon="Icon.ico"
)
includefiles=["file.ogg","file.png",etc]
includes=[]
excludes=[]
packages=[]
setup(
version = "0.0",
description = "No Description",
author = "Name",
name = "App name",
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [exe]
)
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.