Attribute Error while using cx_Freeze - python

while creating exe of my python game . I got the following error
my code in setup.py is
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\Vinayak Singla\\Appdata\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\Vinayak Singla\\Appdata\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6"
executables = [cx_Freeze.Executable("pong.py")]
cx_Freeze.setup(
name="Pongy",
options={"build_exe": {"packages":["pygame","sys","random","time"],"include_files":["boing.wav","out.wav"]}},
executables = executables
)
Can anyone help me to solve this.

You might need a version in your setup script. Like:
cx_Freeze.setup(
name="Pongy",
version='1.0',
options={"build_exe": {"packages":["pygame","sys","random","time"],"include_files":["boing.wav","out.wav"]}},
executables = executables
)
Hope this will solve your problem.

Related

tkinter program compiles with cx_Freeze but program will not launch

I'm trying to create an executable following this tutorial
https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter
After some tweaking I'm able to compile the project but when i click the .exe the mouse loading animation fires but nothing ever loads. This questions has been asked previously but was never resolved.
Where to start looking in the code when your .exe doesn't work after cx_freeze?
My app file
from tkinter import *
from tkinter import messagebox
root = Tk()
root.title('Button')
print("something")
new = messagebox.showinfo("Title", "A tk messagebox")
root.mainloop()
my setup.py
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('SimpleTkApp.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables= [Executable("SimpleTkApp.py", base=base)])
Also I have been manually adding the TCL/TK libraries
set TK_LIBRARY=C:\...\tk8.6 etc
My configuration: python 3.7, cx_Freeze 5.1.1
Any help would be greatly appreciated, I don't even know where to start on this one.
Try to modify you setup.py as follows:
import sys
from cx_Freeze import setup, Executable
import os
PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
include_files = [(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll'))]
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable('SimpleTkApp.py', base=base)]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
options={'build_exe': {'include_files': include_files}},
executables=executables)
This should work for cx_Freeze version 5.1.1 (the current version). In this version, the included modules are in a subdirectory lib of the build directory. If you use 5.0.1 or an earlier version, set
include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]
instead.
See also Getting "ImportError: DLL load failed: The specified module could not be found" when using cx_Freeze even with tcl86t.dll and tk86t.dll added in and python tkinter exe built with cx_Freeze for windows won't show GUI
EDIT:
A further problem is that cx_Freeze has a bug with python 3.7 which is not yet corrected. See Cx_freeze crashing Python3.7.0 . You can find there a link to a bug fix which you should apply manually (according to the OP this solved the problem, see comments).
After trying an even simpler hello world example writing to the console (which also failed) I stumbled across the culprit.
What could be the reason for fatal python error:initfsencoding:unable to load the file system codec?
After updating my freezer.py file with the code found here and using the setup.py provided by jpeg, my example app worked. Thank you both for your swift response.
I have a working setup.py here. Maybe you can try and see if it works after using the same config. Basically sometimes after compiling, the tk and tcl dll/packages are missing and so you need to include them during the setup.
import sys, os
from cx_Freeze import setup, Executable
includes = []
include_files = [r"C:\Users\user\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
r"C:\Users\user\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll"]
base = 'Win32GUI' if sys.platform == 'win32' else None
os.environ['TCL_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(name="simple_Tkinter",
version="0.1",
options={"build_exe":{"includes":[],"include_files":include_files}},
description="Sample cx_Freeze Tkinter script",
executables=[Executable("SimpleTkApp.py",base=base)])

Convert a python3 script in an executable with cx_Freeze

I'm recently made this chat app in python3 and I would like to convert my script in an executable, I made some research and I found and chose cx_Freeze because is multi-platform and I'm currently working with windows 10. I made this script to make the conversion but when I run it nothing happens. If someone could help me out here it will be great thanks!!!
import cx_Freeze
import sys
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("/mis programas/chat/aplicacion1.1.py", base=base, icon="/mis programas/iconos/3.png")]
cx_Freeze.setup(
name = "PyChaT",
options = {"build_exe": {"packages":["tkinter"], "include_files":["/mis programas/iconos/3.png"]}},
version = "1",
description = "Source of communication",
executables = executables
)

Building msi with cx_Freeze : ValueError: FCI error 6

I try to make a msi for my programe with cx_Freeze use python3.5( setup.py bdist_msi ,and get this massege
Screenshot:
Here is my setup.py:
import sys
import os
from cx_Freeze import setup, Executable
build_exe_options = {"optimize": 2,"include_files": ["Frame.py"]}
base = None
if sys.platform == 'win32':base = 'Win32GUI'
os.environ['TCL_LIBRARY'] = r'D:\Python35\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Python35\tcl\tk8.6'
executables = [Executable(script='Frame.py',base=base,)]
can you help me?
Try removing the extra , after base, in this line:
executables = [Executable(script='Frame.py',base=base,)]
Make it:
executables = [Executable(script='Frame.py',base=base)]

Using cx_Freeze to create executable (cannot import _tkinter, DLL load failed)

I am trying to create an executable from my Python project using cx_Freeze, but keep running into this error:
Here's my setup.py:
import cx_Freeze
import os, sys
os.environ['TCL_LIBRARY'] = "D:\\Code\\Python\\3.5.2\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "D:\\Code\\Python\\3.5.2\\tcl\\tk8.6"
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("Main.pyw", base=base)]
includes = ["tkinter"]
include_files = [r"D:\Code\Python\3.5.2\tcl\DLLs\tcl86t.dll", \
r"D:\Code\Python\3.5.2\tcl\DLLs\tk86t.dll"]
cx_Freeze.setup(
name="Test",
version = "1.0",
options={"Test.exe": {"packages":["pygame", "numpy"], "includes": includes, "include_files": include_files}},
executables = executables)
I tried putting tkinter in the "packages" list, but still get the same error. I also checked other StackOverflow posts and used parts of their setup.py code into mine, but nothing is working. I can't use PyInstaller as it doesn't support pygame and py2exe doesn't support Python 3.5. Any help would be appreciated.
Copy and Paste the files (tcl86t.dll, tk86t.dll) to the exe.win .
It worked for me.

import tkinter error

I have a .py file that I am trying to convert into an exe. I have tried numerous tries to build this file using cx_Freeze, but I keep getting the same error every time.
I've heard that it's got something to do with cx_Freeze, so I uninstalled cx_Freeze and reinstalled it using pip install cx_freezexxxx.whl wheel, but that still didn't work. I build my exe by writing python setup.py build in command line. Here's my setup .py code.
import cx_Freeze
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tk8.6"
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("filemakergui.py", base=base, icon="Treetog-I-Documents.ico")]
cx_Freeze.setup(
name = "ALT File Maker",
options = {"build_exe": {"packages":["tkinter"], "include_files":["Treetog-I-Documents.ico", "Hopstarter-Sleek-Xp-Basic-Help.ico", "Custom-Icon-Design-Flatastic-2-Success.ico"]}},
version = "0.01",
description = "ALT File Maker",
executables = executables
)
Is there anything wrong with what I've written in my setup.py file? I've been stuck on this problem for several days now. Any tips on resolving an issue like this?

Categories

Resources