Moving all the DLL and PYD to a sub-folder with cx_Freeze

僤鯓⒐⒋嵵緔 提交于 2019-11-30 12:24:23

I understand your frustration. What I tend to do is take the entire build folder and move it to the program files directory assuming you are using a windows machine. Then create a shortcut on the desktop to the executable. I then generally change the icon to something pleasing to the eye. In other words all the system files are hidden and all you are left with is a single nice looking icon on the desktop.

"manually" did it , but is this the correct way ? i'm on win7 x64 cx_freeze 4.3.2

my init_script, combined from Console.py and ConsoleSetLibPath.py

import encodings
import os
import sys
import warnings
import zipimport

paths = os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep)
if DIR_NAME not in paths:
    paths.insert(0, DIR_NAME)
    os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(paths)
    os.execv(sys.executable, sys.argv)

sys.frozen = True
sys.path = sys.path[:4]

# i added this line
sys.path.append(r'lib')

os.environ["TCL_LIBRARY"] = os.path.join(DIR_NAME, "tcl")
os.environ["TK_LIBRARY"] = os.path.join(DIR_NAME, "tk")

m = __import__("__main__")
importer = zipimport.zipimporter(INITSCRIPT_ZIP_FILE_NAME)

# The following if/else is copied from ConsoleSetLibPath.py
if INITSCRIPT_ZIP_FILE_NAME != SHARED_ZIP_FILE_NAME:
    moduleName = m.__name__
else:
    name, ext = os.path.splitext(os.path.basename(os.path.normcase(FILE_NAME)))
    moduleName = "%s__main__" % name

code = importer.get_code(moduleName)
exec code in m.__dict__

versionInfo = sys.version_info[:3]
if versionInfo >= (2, 5, 0) and versionInfo <= (2, 6, 4):
    module = sys.modules.get("threading")
    if module is not None:
        module._shutdown()

Then i save this file in C:\Python27\Lib\site-packages\cx_Freeze\initscripts as ConsoleSetLibPathx.py and in my setup.py

setup(
    name = 'xxx',
    version = '0.1',
    options = {'build_exe': {'includes':includes,
                             'excludes':excludes,
                             'packages':packages,
                             'include_files':includefiles,
                             'create_shared_zip':True,
                             'include_in_shared_zip':True,
                              # use the "hacked" init_script ?
                             'init_script':'ConsoleSetLibPathx',
                             'include_msvcr':True,
                             }

                             }, 
    executables = [exe]
)

# Am i supposed to do the mkdir lib , and copy *.pyd *.dll into it in the end of this setup.py here? 
# I verified this is working by manually creating lib dir and copy all files inside, it works.

i feel i should do it in the options, or somewhere, but don't quite understand the cx_freeze doc right now. maybe --target-dir or --default-path or --replace-paths ? not sure how to use them

edit: sorry this needs improving, when i test this in another clean win7 in vmware, it's working but it's acting weird, my code of non-blocking read keypress is not working. not sure which part is wrong.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!