Run time error with twisted and cx_freeze - python

I am currently trying to freeze some python code using twisted with cx_freeze.
I have this in my python file Main.py :
print('Start')
import twisted.internet
input('End')
and this in setup.py file :
import sys
from cx_Freeze import setup, Executable
includes = ["twisted.internet", "twisted.internet.protocol", "pkg_resources"]
excludes = []
packages = []
namespace_packages = ["zope"]
build_exe_options = {"packages": packages, "excludes": excludes, "includes": includes, "namespace_packages": namespace_packages, "append_script_to_exe":True}
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
setup( name = "xxx",
version = "1.0",
author = "xxx",
author_email = "xxx",
description = "xxx",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py", base=base, icon = None)])
I keep getting a run time error R6034 when I run my compiled program. Someone knows why ?

In the end, I used a workaround. I figured out that the file zope.interface._zope_interface_coptimizations was the root of the issue (it fails to load) so I excluded it in my setup.py file :
excludes = ["zope.interface._zope_interface_coptimizations"]
It now works well but the initial problem is not solved and I fear I would need this package at some point.

Related

Python 3.6 After converting tkinter to exe - SSH function stopped working

After I did the convert to exe, ssh(paramiko) function does not work anymore. It does not connect to the device.
I have included paramiko and socket packages. Any Idea?
it is working in with non-converted version.
setup.py file
import cx_Freeze
from cx_Freeze import setup, Executable
import os
import sys
includes = []
include_files = ["C:\\Python36-32\DLLs\\tcl86t.dll",
"C:\\Python36-32\DLLs\\tk86t.dll",
"C:\\Gustavo\\PyCharmPortable\\new\\cpass.ico",
"C:\\Gustavo\\PyCharmPortable\\new\\py2.py",
"C:\\Gustavo\\PyCharmPortable\\new\\py3.py",
"C:\\Gustavo\\PyCharmPortable\\new\\tn.py",
"C:\\Gustavo\\PyCharmPortable\\new\\file1.csv"]
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = "C:\\Python36-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Python36-32\\tcl\\tk8.6"
base = 'Win32GUI' if sys.platform == 'win32' else None
setup(name='Password Change', version='0.1', description='Password Change',
options={"build_exe": {"packages": ["tkinter","paramiko","PIL","socket","telnetlib"], "includes": includes, "include_files": include_files}},
executables=[Executable('cp.py', base=base)])
try including the socket.py/socketserver.py and the _multiprocessing.pyd/_tkinter.pyd/_socket.pyd, this is what worked for me.
include_files = [
"C:\\Python36-32\DLLs\\tcl86t.dll",
"C:\\Python36-32\DLLs\\tk86t.dll",
"Python36/Lib/socket.py",
"Python36/Lib/socketserver.py",
"Python36/DLLs/_multiprocessing.pyd",
"Python36/DLLs/_tkinter.pyd",
"Python36/DLLs/_socket.pyd",
"C:\\Gustavo\\PyCharmPortable\\new\\cpass.ico",
"C:\\Gustavo\\PyCharmPortable\\new\\py2.py",
"C:\\Gustavo\\PyCharmPortable\\new\\py3.py",
"C:\\Gustavo\\PyCharmPortable\\new\\tn.py",
"C:\\Gustavo\\PyCharmPortable\\new\\file1.csv",

Can't make a setup.py file with multiplataform-compiled external modules

I'm trying to run cx_freeze with a plataform-agnostic setup.py file, i can't figure how to add the compiled files (.pym, .so) into the executable
DataProcessor is a python module compiled externally by Cython ... but i don't know how to include it in cx_freeze executable beacause the absolute path depends upon plataform and python version. So how can i handle that.
the executable is compiled but the external module is not include so when i ran the application throws an error that DLL is not loaded or in case of MacOS says ModuleNotFoundError: No module named 'DataProcessor'
EDIT: i have seen an error on the original setup.py, correcting this error cx_freeze shows this error
cx_Freeze.freezer.ConfigError: cannot find file/directory named DataProcessor
EDIT2: as suggested by #mgracer tried to put in in includes section but no sucess cx_freeze shows
ImportError: No module named 'DataProcessor'
so what i can i do to maintain my setup.py plataform-agnostic.
This is what i have until now
from Cython.Build import cythonize
from cx_Freeze import setup, Executable
import sys
import os.path
# Windows hack
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
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')
# Windows hack
includes = []
excludes = ['tkinter']
packages = ['openpyxl', 'sqlite3', 're', 'collections', 'os']
include_files = ['DataProcessor']
dll_excludes = []
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"excludes": excludes,
"includes": includes,
"packages": packages,
"include_files": include_files
}
setup(
name="analizador",
version="0.1",
description="Foo bar",
options={"build_exe": build_exe_options},
ext_modules=cythonize("DataProcessor.pyx"),
executables=[Executable("analisis.py", base=base)]
)
i solved it extending a little the setup.py script
resulted in this:
from Cython.Build import cythonize
from cx_Freeze import setup, Executable
import sys
import os
import platform
# hack para correr en windows
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
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')
# hack
setup(ext_modules=cythonize("DataProcessor.pyx"))
# rutina detect the files
arch = platform.machine()
temp = platform.python_version_tuple()
pyver = '%s.%s' % (temp[0], temp[1])
pname = None
pext = ".so"
tfiles = ()
if sys.platform == 'darwin':
temp = platform.mac_ver()
tver = '.'.join(temp[0].split('.')[:2])
ptemp = 'macosx'
pname = '%s-%s-%s' % (ptemp, tver, temp[2])
if sys.platform == 'win32':
ptemp = 'win'
pname = '%s-%s' % (ptemp, arch.lower())
pext = '.pym'
libpath = os.path.join('build', ('lib.%s-%s' % (pname, pyver)))
afiles = os.listdir(libpath)
for file in afiles:
afile = file.split('.')
tfiles = tfiles + ((os.path.join(libpath, file), '.'.join([afile[0],
afile[2]])),)
# end
includes = []
excludes = ['tkinter', 'PyQt4']
packages = ['openpyxl', 'sqlite3', 're', 'collections', 'os']
dll_excludes = []
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"excludes": excludes,
"includes": includes,
"packages": packages,
"include_files": tfiles
}
setup(
name="foo",
version="0.1",
description="Foobar",
options={"build_exe": build_exe_options},
executables=[Executable("analisis.py", base=base)]
)

Possible uiloader issue when converting pyside app using cx_freeze

I am trying to convert a pyside app to an executable (.exe) on Windows using cx_freeze. The packaging works with no problem, but when starting the generated .exe file, I get the following error:
ImportError: could not import module "PySide.QtXml"
When I try to convert the app shipped with cx_Freeze\Samples\PyQt4, it runs with no problems.
In this sample application there is just a simple QDialog called, but in my application I used QtDesigner for GUI design and I load it with PySide UiLoader directly in my py.file:
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self)
loader = QUiLoader()
self.ui = loader.load('xxxx.ui',self)
QMetaObject.connectSlotsByName(self)
setup.py
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
from cx_Freeze import setup, Executable
from PySide import QtXml
base = 'Win32GUI' if sys.platform=='win32' else None
options = {
'build_exe': {
'includes': 'atexit'
}
}
build_exe_options = {
'includes': ['atexit'],
}
executables = [
Executable('xxx.py', base=base)
]
setup(name='xxx',
version = '0.10',
description = 'First try',
options = dict(build_exe = buildOptions),
executables = executables)
In my opinion there's some problem using UiLoader when converting with cx_freeze but I have no clue how to overcome this issue.
This seems to be an old question. Still I am answering as it would help someone who is looking for a solution.
The solution is so simple that you just need to add "PySide.QtXml" to the includes list. After this your setup.py will look like this
build_exe_options = {
'includes': ['atexit'],
'packages': ['PySide.QtXml'],
}

Using CX_Freeze with Scipy: scipy.special._ufuncs.py

I am having problems freezing a programm of mine. I narrowed it down to the scipy module. The porgramm I am trying to freeze is:
from scipy import signal
signal.hann(1000)
My setup script is:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Some name",
version = "1.0",
author="My name",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("Script_Name.py", base=base)])
# ^CHANGE THIS NAME!!!
Here is a picture of the error message. I also tried including scipy.signal in the setup file as
build_exe_options = {"includes":"scipy.signal"}
but it didn't do any good. Please help me.
I had a similar problem which could be solved by making sure that:
1 The build directory contains a file named _ufunc.pyd (instead of scipy.special._ufuncs.pyd as mentioned above). You can achieve this by specifying the build_exe_options:
build_exe_options = { 'packages': ['scipy'],
"include_files": [('path2python\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd')]}
2 Making sure that all dlls used by ufunc.pyd are also in the build directory. In my case libifcoremd.dll adn libmmd.dll were failing. You can check this with dependencywalker
I hope this helps you out.

Cx_Freeze - How to Include Modules

I've been having this problem with including things into my cx_Freeze script, what im trying to do is include easygui and sys, as i use them in my program. Any help would be appreciated!
Heres the code:
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 = "ProgramGUI",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("ProgramGUI.py", base=base)])
So really all i need to know is how to incorparate Includes[ "sys", "easyGUI" ] Into the setup script :D
Seriously, I think you just miss a small thing to tell cx_freeze to import easy_gui:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {
"packages": ["os", "sys"],
"excludes": ["tkinter"],
"includes": ["easy_gui"] # <-- Include easy_gui
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "ProgramGUI",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("ProgramGUI.py", base=base)])

Categories

Resources