cx-Freeze executable ImportError: No module named 'zipfile' - python

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

Related

Python cx_Freeze import _tkinter and ImportError: DLL load failed %1 is not a valid win32 application ERROR

cx_Freeze import _tkinter #if this fails your python may not be configurated for Tk.. ImportError: DLL load failed: %1 is not a valid win32 application
Hi! I created a word guessing/memorizing language practice program in tkinter, and i wanted to convert it to an executable app but i get errors again and again... I tried at least 10-15 different ways but it is still same. So i googled all the similar topics and tried every single suggestion but they did not work for me. I tried pyinstaller as well. It does not give an error but also it does not run the executed app either. When i click on the app.exe, black CMD screen appears then disappears and it creates the csv file to save the words. So i changed to cx_Freeze but it does not work either.
What have i tried?
For pyinstaller:
I converted my app.py to app.exe by using pyinstaller -F app.py and pyinstaller app.py, but none of them worked.
For cx_Freeze
1- I tried my old setup.py (which worked to convert my all games to .exe) but it did not work on this, i guess it is about tkinter. Because my games were written with pygame, i did not use tkinter for anything.
2 -I tried at least 10 different setup files shared by you guys on stackoverflow and other websites. But they did not work either.
3- I tried to set environment
4- I tried to specify environment
5- I copied tcl86t.dll and tk86t.dll files from the python dlls to my app directory and added them as included files in the setup.py
6- I deleted 64bit version and i only have 32bit version of python3.7
and more and more...
So this is my current setup.py
import sys,os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = "C:\Python37\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\Python37\tcl\tk8.6"
build_exe_options = {"packages": ["os"],"includes":["tkinter"],"include_files": []}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "App",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)]
)
I use Windows7 64bit and Python 3.7.1 32bit and 3.7.0 64bit
So what should i do? I am stuck here. I really gave up and asking a new question on here. Please help me guys.. Thanks in advance.

Using cx_Freeze with Graphviz dependency

I have a python program that uses the Graphiz module, the output of the program uses the Graphviz windows installation to create an image.
My program is for average windows users and my goal is to deliver one msi installer.
I don't have issues using the cx_Freeze to pack my python modules and run the outcome afterwards...
The problem is, the program depends on the installed Graphviz dir to create the image from my programs output moreover the dir's bin folder should be in the system path....
If there is a solution using cx_Freeze (and I tried and didn't find one)
pls help me
If not pls advice how can I circumvent this problem
Thanks a million!
import sys, os
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["PIL.Image",
"tkinter",
"graphviz",
"Rec_FFT",
"graph_visualization",
"math",
"cmath"],
"include_files": [
r"D:\Yigal\Python36-32\DLLs\tcl86t.dll",
r"D:\Yigal\Python36-32\DLLs\tk86t.dll"],
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
# pass # base=None is for console apps
os.environ['TCL_LIBRARY'] = r'D:\Yigal\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Yigal\Python36-32\tcl\tk8.6'
setup(name="FFTCalc",
version="0.1",
description="# Rec FFT Calc #",
options={
"build_exe": build_exe_options
},
executables=[Executable("Rec_FFT_GUI.py", base=base)])
This is the output when Graphiz is not installed:
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tjpeg', '-O', 'FFT_RESULTS\\graph'], make sure the Graphviz executables are on your systems' PATH
I can see it is missing the dot.exe ... but how can I pack it with cx_Freeze??

Errors when freezing a Python application with cx_Freeze

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.

Error in opening Python executable file, created using cx_freeze

Before asking this question have checked other queries (cx_freeze ImportError when executing file) was related to my issue, error was "DLL load failed" but my case is "No module named".
My question is - I have created a Python executables using cx_freeze but when I open the Main.exe file, the application opens with Traceback errors on it..
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"optimize": 2,
"includes": [],
"compressed": True,
"copy_dependent_files": True,
"create_shared_zip": False,
"append_script_to_exe": True,
"include_in_shared_zip": False,
"include_files":[('vPlot.ui'),
('vPlot.py'),
('company.jpg')],
"include_msvcr": True,
"packages": [],
}
# 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 = "plcTest",
description = "plcTest!",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py",
base=base,
copyDependentFiles=True,
appendScriptToExe=True)])
my error is (http://i.imgur.com/TSVg6Ft.png), I can't find the file "'matplotlib.backends.backend_tkagg'", please give your advise, thanks in advance
cx-freeze have good module analysis but sometimes it is fails. Especially back and modules.
Matplotlib uses tkagg (i am not sure it is package name)as backend gui module. To solve this, you have two options;
1- import missing package somewhere in your code
2- pass package name to cx-freeze as parameter.
Example: i used cx-freeze from command-line
cxfreeze FooMain.py --include-module=simplejson, lxml # FooMain.py my main script
edit: using python build_exe_options
"packages": ["simplejson", "lxml"],

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