Working on GUI on Python (3.6.5 on win32), PyQt5 (5.10.1), use cx_Freeze (5.1.1).
There is function to use printers.
py :
def goPrinter(self):
print("___goPrinter")
printer = QtPrintSupport.QPrinter()
print(printer)
print(printer.printerName())
print(QtPrintSupport.QPrinterInfo.availablePrinterNames())
print("return")
When I run py - script, printer works fine.
cmd:
-__goPrinter
-PyQt5.QtPrintSupport.QPrinter object at 0x02FF1EBO>
-Microsoft XPS Document Writer
-['Microsoft XPS Document Writer', 'FAX']
-return
When I run exe file (after cx-Freeze), any printers are invisable. Printing doesn't work.
cmd:
-__goPrinter
-PyQt5.QtPrintSupport.QPrinter object at 0x02BB23B0>
-
-[]
-return
setup.py script for creating exe:
from cx_Freeze import setup, Executable
executables = [Executable('KIWI_1105.py',
targetName='KIWIv17.exe',
icon='iconsN\capsule.ico',
shortcutName='KIWI',
shortcutDir='DesktopFolder'
)]
excludes = ['email', 'http', 'urllib', 'unittest']
zip_include_packages = ['collections','distutils', 'encodings',
'importlib', 'logging', 'imageformats',
'platforms', 'PIL', 'pydoc_data', 'PyQt5', 'xml']
include_files = ['iconsN', 'Atlas']
options = {
'build_exe': {
'excludes': excludes,
'zip_include_packages': zip_include_packages,
'include_files': include_files,
'include_msvcr': True,
'build_exe': 'KIWI',
}
}
setup(name='KIWI App',
author='23',
version='17.1505',
description='KIWI Viewer Application',
executables=executables,
options=options)
Related
I've built an app using Tkinter, and when compiling it with cx_Freeze I get no issues.
When I run the .exe generated on my machine, and my virtual test machine, I have no issues. However, someone currently testing my app is encountering this issue:
Previously they had been encountering this issue:
I fixed the issue of 'brotlicffi' not being found by bypassing py7zr by throwing it into a try statement, as it's not completely essential for the app to function. However, cefpython3 is.
What I find very confusing is that the paths in the traceback errors are all my paths, I've encountered this before with cx_Freeze, which threw me off at first but dismissed it as a possible quirk of cx_Freeze/Python.
Here is my cx_Freeze setup.py:
dir_path = os.getcwd()
interface_path = os.path.join(dir_path, "interface")
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {"build_exe": {
"packages": [
"base64",
"re",
"os",
"inspect",
"_winapi",
"json",
"time",
"selenium",
"webdriver_manager",
"tqdm",
"pdfrw",
"cefpython3",
"customtkinter",
"tkinter",
"pyglet",
"urllib",
"py7zr",
"brotli",
"brotlicffi", # Needed for py7zr
"winreg",
"requests",
"shutil",
"stat",
"inspect"
],
# "path": [
# "C:\\Users\\aaron\\PycharmProjects\\slowly scraper\\venv\\Lib\\site-packages"
# ],
"include_files": [
# "yellow.json",
("venv\\Lib\\site-packages\\brotli.py", "lib\\brotli.py"),
"interface"
# "cefpython3"
]
# "replace_paths": [("*", "")]
}
}
executables = [cx_Freeze.Executable(
"main.py",
base=base,
target_name="SLD.exe",
icon=os.path.join(interface_path, "SLD_icon.ico")
)
]
cx_Freeze.setup(
name="Slowly Letter Downloader",
options=options,
author="PastaSource",
version="0.1",
description="Automates the downloading of letters from Slowly",
executables=executables
)
If it helps, I'm running this all in Pycharm, the includes the compilation of the cx_Freeze application.
I want to compile a python script using the cx_Freeze module. For this I write the following setup.py file:
from cx_Freeze import setup, Executable
executables = Executable(script = "Example5.py",icon = "icon.ico")
zip_include_packages = ["collections", "importlib", "encodings"]
excludes = [
'unicodedata', 'logging', 'unittest', 'email', 'html', 'http', 'urllib',
'bz2'
]
options = {
"build_exe": {
"include_msvcr": True,
"excludes": excludes,
"zip_include_packages":zip_include_packages,
"build_exe": "Test compiling",
}
}
setup(
name='Test',
version='1.0.0',
description='Testing compile',
executables=[executables],
options=options
)
This script doesn't want to compile, cx_Freeze is failing with error:
Fatal Python error: Py_Initalize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000bf4 (most recent call first)
But if I replace this line:
executables = Executable(script = "Example5.py",icon = "icon.ico")
by:
executables = Executable(script = "Example5.py")
the script is working and creates a .exe file.
I don't understand why the icon is not set.
Source code: https://github.com/Bus-Artyom/Test_compile
Thank you in advance.
It seems that your icon.ico is not a valid .ico file (but rather a .png file which has been renamed to .ico?).
Try with a valid .ico file.
I have successfully compiled my python file to cx_Freeze, but when I click on the application I get the following error:
error image link
Here is my setup.py:
import sys
from cx_Freeze import setup, Executable
company_name = 'Vagif Programs'
product_name = 'BananaCell'
bdist_msi_options = {
'upgrade_code': '{66620F3A-DC3A-11E2-B341-002219E9B01E}',
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (company_name,
product_name),
}
build_exe_options = {
'includes': ['tkinter', 'tkinter.filedialog', 'openpyxl.utils'],
}
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
exe = Executable(script='comparing.py',
base=base,
icon='icon.ico',
shortcutName='BananaCell',
shortcutDir='DesktopFolder'
)
setup(name=product_name,
version='1.0.0',
description='blah',
executables=[exe],
options={
'bdist_msi': bdist_msi_options,
'build_exe': build_exe_options})
Can anyone help me? Any help would be appreciated.
First of all, the technical stuff:
Python : 3.3
cx_freeze : 4.3.2
I have looked through several setups, but accomplished nothing. So far I only get a very quickly closing Python Command Line, and sigh, no exe.
The setup.py:
from cx_Freeze import setup, Executable
executables = [
Executable("Swiss Rounds.py", appendScriptToExe=True, appendScriptToLibrary=False)
]
buildOptions = dict(
create_shared_zip = False)
setup(
name = "hello",
version = "0.1",
description = "the typical 'Hello, world!' script",
options = dict(build_exe = buildOptions),
executables = executables)
Thank you people!
It looks like you forgot the base for your executable, so cx freeze doesn't know how to make the exe. This is how I structure my setup.py file. This setup will put the exe in a different folder if it is 32 bit.
import os, sys, platform
from cx_Freeze import setup, Executable
targetDir = "./build/"
build_exe_options = {
"icon": "/assets/images/icon.ico",
"build_exe": "/build/",
"packages": [],
"includes": ["re", "os", "atexit"],
"include_files": ["/assets/"],
"excludes": ["tkinter", "ttk", "socket", "doctest", "pdb", "unittest", "difflib",
"_bz2", "_hashlib", "_lzma", "_socket"],
"optimize": True,
"compressed": True,
}
is32bit = platform.architecture()[0] == '32bit'
if is32bit:
targetDir = "./buildX86/"
build_exe_options["build_exe"] = targetDir
# end
base = None
if sys.platform == "win32":
base = "Win32GUI"
# end
setup( name = "MyProgram",
version = "0.1",
description = "My program example",
options = {"build_exe": build_exe_options},
executables = [ Executable("/myprogram.py",
targetName="MyProgram.exe",
targetDir=targetDir,
base=base) ]
)
Run:
python setup.py build
I want to create a .exe file. I'm using Python 2.7.3 with wxPython for the GUI. I've installed py2exe for Python 2.7 and tried to create a .exe file following the tutorial at http://www.py2exe.org/index.cgi/Tutorial
When I try to run my created .exe file, I get following error:
File "wx\_gdi.pyc",line823, in BitmapFromImage wx._core.PyAssertionError:
C++ assertion "image.OK()" failed at ..\..\src\msw\bitmap.cpp(802) in
wxBitmap::CreateFromImage(): invalid image
So I looked into my code and the following line is causing the problem:
self.bmpSun = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(wx.Image('images/sun.gif', wx.BITMAP_TYPE_ANY)), pos = (0,0))
When I browse to the source folder and run the main.py file myself, my app runs fine. I haven't found any help online so far. Can anybody solve this problem/suggest reliable alternatives for py2exe? Thank you.
The line that errors out is looking for an image in the Images folder. That's a path relative to the .exe file created by py2exe. So you need to be sure that that folder exists in correct position relative to the exe, and that it is populated with the images you are going to use. You can do this 2 ways. Either copy the folder to where the exe will reside, or use the data_files keyword arg in the script that makes the .exe. Here's the pertinent part of one of my setup scripts, showing a data_files list of tuples and use of the data_files keyword arg later:
data_files = [('Images', glob('Images/*.*')),
]
includes = ['win32com.decimal_23', 'datetime']
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter', 'unittest']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll','MSVCP90.dll']
setup(
data_files = data_files,
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 1,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile = None,
windows = [filename]
)