Errors when freezing a Python application with cx_Freeze - python

I'm trying to build a program in Python 3.6, but I've been struggling to get a functional .exe out. The packing script looks like it completes, but the resulting program instantly crashes. I've had similar issues with py2exe and pyinstaller even when using earlier versions of python 3, but I was able to get the following error out of cx_freeze 5.0.1's executable:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000019a0 (most recent call first):
Searching around this has been mentioned before in relation to unix systems, but I'm doing this on Windows 10?
Here's the packaging script:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Program Files (x86)\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files (x86)\\Python36-32\\tcl\\tk8.6"
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
base = None
#'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('WorkingScript.py', base=base, targetName = 'WorkingScript.exe', icon='IconSml.ico')]]
includefiles=["Logo3.png", "Image4.png", "IconSml.ico"]
setup(name='WorkingScript',
version = '0.9',
description = 'This time around',
options = dict(build_exe = buildOptions),
executables = executables)
The only modules my program imports are tkinter, PIL, os, threading, csv and xml.dom.

Related

cx_Freeze pygame error

i've recently started working with pygame and wanted to create an executable using cx_Freeze but i encounter an error every time i try to run my exe file.
Fatal Python error: initfsencoding: unable to load the file system codec
ImportError: invalid flags 1530097318 in 'encodings'
Current thread 0x000016f0 (most recent call first):
Here's my setup.py file:
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "C:\\Python37-64\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Python37-64\\tcl\\tk8.6"
executables=[cx_Freeze.Executable('snk.py')]
cx_Freeze.setup(
name='Snake',
options={'build_exe':{'packages':['pygame'], 'include_files':['beep.wav', 'lost.wav', 'apple.png', 'snakehead2.png', 'apple2.png', 'tail.png', 'C:\\Windows\\Fonts\\MAGNETOB.TTF']}},
description='Snake Game',
executables=executables
)
Can someone please help.
As I answered here.You are using python 3.7. As far as I have tested , modules like pyinstaller and cx_freeze don't seem to be working in this version. Try uninstalling your python (don't forget to backup your files before), and installing python 3.6.3 or any other python 3 version except python 3.7.

error: [Errno 2] No such file or directory: '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl'

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.

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 executable ImportError: No module named 'zipfile'

I'm on Windows 7, as are all potential users of my program. I packaged a Python program I wrote into an executable file using cx_Freeze, with the following command:
python setup.py build
This generates a build directory that contains my_program.exe. The executable works flawlessly on my computer, but on a coworker's machine, it throws an exception:
ImportError: No module named 'zipfile'
Here's my setup.py, where zipfile is explicitly included (and it's definitely in library.zip):
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name='Z-Wizard',
version='0.1',
description='Z1/Z2 data extraction tool',
author='Liz Rosa',
author_email='me#url',
options = {
'build_exe': {
'packages': ['zipfile']
}
},
executables = [Executable('my_program.py', base=base)]
)
The traceback is quite long; there's a screenshot at the URL below. It apparently involves a series of functions in _bootstrap.py. I'm not quite sure what's going on here. Also, "C:\Users\lizr..." is my home directory, not hers. Why does it appear in the traceback on her computer? In case it's not obvious, I don't know much about the freezing process.
http://i.imgur.com/cAQKWxq.png

Cannot find module "cx_freeze__init__" when freezing Python script

So I am trying to freeze a Python script as an .exe. I installed cx_freeze to do so as I am using 3.4. I created the setup.py file successfully and also ran the build which appears in the build folder and .exe appears. However, when I open the .exe it displays the following error:
zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal python error: unable to locate initialization module
Current thread 0x00001d58 <most recent call first>:
I believe I did everything else correctly. There is indeed a cx_Freeze_init_.pyc file in the library.zip, however it cannot find it for some reason. The only other error I had was that certain modules were missing when during the cmd build:
Missing modules:
? _dummy_threading imported from dummy_threading
? ce imported from os
? doctest imported from heapq
? getopt imported from base64, quopri
? org.python.core imported from copy
? os.path imported from os
? posix imported from os
? pwd imported from posixpath
? subprocess imported from os
This is not necessarily a problem - the modules may not be needed on this platfo
rm.
This is the setup.py I used:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
base = 'Console'
executables = [
Executable('guess.py', base=base)
]
setup(name='Guess',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
Thanks in advance!

Categories