「手動」做到了,但這是正確的方法嗎?我是在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中測試這個,它的工作,但它的行爲怪異,我的非阻塞閱讀按鍵代碼無法正常工作。不確定哪部分是錯誤的。
查看[ConsoleSetLibPath](https://bitbucket.org/anthony_tuininga/cx_freeze/src/default/cx_Freeze/initscripts/ConsoleSetLibPath.py)initscript。應該可以調整以查找子文件夾中的庫。 – 2014-01-08 17:26:55
你如何使用這個initscript?它看起來很有希望,但我不知道如何整合它。 – ibell 2014-01-08 20:01:22
如果您使用的是setup.py腳本,請爲'build_exe'指定'init_script'選項([docs](http://cx-freeze.readthedocs.org/en/latest/distutils)。HTML#集結EXE))。或者如果您使用'cxfreeze'命令,則會有[--init腳本標誌](http://cx-freeze.readthedocs.org/en/latest/script.html#cmdoption--init-script) 。 – 2014-01-08 22:43:52