“手动”做到了,但这是正确的方法吗?我在 win7 x64 cx_freeze 4.3.2
我的 init_script,结合自Console.py
和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()
然后我将此文件保存在我C:\Python27\Lib\site-packages\cx_Freeze\initscripts
的ConsoleSetLibPathx.py
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.
我觉得我应该在选项中或某个地方这样做,但现在不太了解 cx_freeze 文档。也许 --target-dir 或 --default-path 或 --replace-paths ?不知道如何使用它们
编辑:抱歉,这需要改进,当我在 vmware 中的另一个干净的 win7 中测试它时,它正在工作,但它的行为很奇怪,我的非阻塞读取按键代码不起作用。不确定哪个部分是错误的。