使用cx_Freeze将所有DLL和PYD移至子文件夹 [英] Moving all the DLL and PYD to a sub-folder with cx_Freeze

查看:129
本文介绍了使用cx_Freeze将所有DLL和PYD移至子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cx_Freeze邮件列表中出现了很多次



(请参阅



cx_Freeze和移动文件



冻结Python应用程序时创建的文件更少



cx_freeze python单个文件?



在我看来,这应该是一个简单的解决方法,但我不知道如何开始。 p>

我有一个python应用程序,它依赖scipy,wxpython,numpy和一堆其他软件包,每个软件包都有很多动态链接的库。 PYD和DLL文件使主要的可执行文件文件夹变得混乱不堪,甚至很难在所有文件中找到可执行文件。我的用户不是特别精通计算机,因此清晰性非常重要。



我不需要像bbfreeze那样理论上可以生成的单个可执行文件。我喜欢distutils setup.py文件如何与cx_Freeze一起使用,以及cx_Freeze的其他用途非常出色。



我想要的是清理主可执行文件的一种方法夹。我将完全满意手动将DLL文件移动到Frozen_libs文件夹或其他内容,然后调整共享库的加载路径,以帮助它找到动态库(如果可能)。或类似的东西。



谢谢

解决方案

手动完成了,但这是正确的方法吗?我正在使用win7 x64 cx_freeze 4.3.2



我的init_script,结合了 Console.py ConsoleSetLibPath.py

 导入编码
导入os
导入sys
导入警告
导入zipimport

路径= os.environ.get( LD_LIBRARY_PATH,).split(os.pathsep)
如果DIR_NAME不是在路径中:
path.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]

#我在这行中添加了
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)

#以下如果/否则从ConsoleSetLibPath.py
复制,如果INITSCRIPT_ZIP_FILE_NAME!= SHARED_ZIP_FILE_NAME:
mod uleName = m .__ name__
else:
名称,ext = os.path.splitext(os.path.basename(os.path.normcase(FILE_NAME)))
moduleName =%s__main__ %名称

代码= importer.get_code(moduleName)
m .__ dict__中的执行代码

versionInfo = sys.version_info [:3]
如果versionInfo> =(2、5、0)和versionInfo< =(2、6、4):
module = sys.modules.get( threading)
如果module不是None :
module._shutdown()

然后我将该文件保存在 C:\Python27\Lib\站点软件包\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 e_shared_zip':真的,
‘include_in_shared_zip':真的,
#使用被入侵的init_script吗?
'init_script':'ConsoleSetLibPathx',
'include_msvcr':True,
}

},
可执行文件= [exe]


#我是否应该执行mkdir lib,并在此setup.py的末尾将* .pyd * .dll复制到其中?
#我通过手动创建lib dir并复制其中的所有文件来验证此方法是否有效。

我觉得我应该在选项中或某个地方这样做,但不太了解cx_freeze doc现在。也许--target-dir或--default-path或--replace-paths吗?不知道如何使用它们



编辑:对不起,这需要改进,当我在vmware中的另一个干净的win7中对其进行测试时,它正在工作,但表现得很奇怪,我的代码不-阻止读取按键不起作用。不知道哪一部分不对。


This has come up quite a few times on the cx_Freeze mailing lists

(see

cx_Freeze and moving files around

Creating fewer files when freezing a Python application

cx_freeze python single file? )

and it seems to me like it ought to be a simple fix, but I can't see how to begin.

I have a python application that depends on scipy, wxpython, numpy and a bunch of other packages that each have a LOT of dynamically linked libraries. The main executable folder gets very cluttered with PYD and DLL files and it is hard to even find the executable amongst all the files. My users are not particularly computer savvy, so clarity is very important.

I don't require a single executable like can theoretically be generated by bbfreeze. I like how the distutils setup.py file works with cx_Freeze and in every other way cx_Freeze is pretty much brilliant.

All I want is a way to clean up the main executable folder. I would be completely happy with manually moving the DLL files into a freeze_libs folder or something and then munging the shared library loading path to help it find the dynamic libraries if that is possible. Or something like that.

Thanks

解决方案

"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.

这篇关于使用cx_Freeze将所有DLL和PYD移至子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆