python - how to bundle .py files launched with execfile() on py2exe? -
i'm developing small tool on python launches set of scripts on folder. need package on stand-alone binary , i'm using py2exe it.
my current code use os.path.listdir() .py files on folder, , launch of them using execfile() funcion based on user input on pyqt interface.
my code works expected if executed through main python file, fails when compiled py2exe. exception is:
ioerror: [errno 2] no such file or directory for python files launched execfile().
i'm bundling "bundle_files": 1 , zipfile = none. tried include these files messing includes , packages without luck. can me configure py2exe properly?
this current setup.py:
from distutils.core import setup import py2exe import os #python modules excluded binary file mod_excludes = [ "tkinter", "doctest", "unittest", "pydoc", "pygments", "pdb", "email", "_ssl", "difflib", "inspect" ] #avoid adding dependencies dll_excludes = [ "msvcp90.dll", "w9xpopen.exe" ] #force exe mod_includes = [ "sip" ] package_includes = [ "app.payloads" ] py2exe_options = { "optimize": 2, # 0 (none), 1 (-o), 2 (-oo) "includes": mod_includes, "excludes": mod_excludes, "dll_excludes": dll_excludes, "packages": package_includes, #"xref": false, "bundle_files": 1, "compressed": true #"dist_dir": dist_dir } #todo generar automaticamente la interfaz setup( windows=[{"script": "app.py", "icon_resources": [(1, "app/gui/res/app.ico")], "uac_info": "requireadministrator"}], data_files=exe_files, options={"py2exe": py2exe_options}, zipfile=none ) and i'm getting following traceback:
traceback (most recent call last): file "app\gui\ui.pyo", line 22, in call_report file "app\core\core.pyo", line 32, in generate_report file "app\core\core.pyo", line 18, in launch_payload ioerror: [errno 2] no such file or directory: 'c:\\users\\my_user\\path\\to\\app\\dist\\app.exe\\app\\payloads\\autoruns.py'
py2exe includes *.pyc files (or .pyo files if use "optimize" greater 0 do). since error message mentions non existing *.py file:
ioerror: [errno 2] no such file or directory: 'c:\users\my_user\path\to\app\dist\app.exe\app\payloads\autoruns.py'
, might reason.
in general, recommend not use execfile(). rather write own package. py2exe include package automatically if import somewhere in application code. package should contain files want load dynamically. can use code:
my_module = __import__('my_package.module_name') the string 'module_name' can come user input through gui.
Comments
Post a Comment