cx_Freeze - how do I convert multiple files into the build folder

前提是你 提交于 2019-12-02 04:50:58

问题


I've made a program which launches another python program using os.startfile().

I wanted to have this as two exe files, launching the second by using subprocess.call() instead, in 1 build folder but I don't know how to do this.

I tried making a setup file for both, creating 2 build folders and then copying 1 of the exe files into the other's build folder but got this:

Traceback (most recent call last): 
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 12, 
in <module> __import__(name + "__init__") 
ImportError: No module named 'menu_record__init__'

Have any ideas?


回答1:


It is possible to include two exe in one build with the following method:

import sys
from cx_Freeze import setup, Executable

options = {
'build_exe': {'path': sys.path + ['modules']}
}

executables = [
    Executable('script_1.py'),
    Executable('script_2.py')]

setup(
    name='two exe in one folder',
    version='0.1',
    description='Two exe in a single build folder',
    options=options,
    executables=executables)

You will probably have to edit this script further but it should produce two exe in the same build folder.

An example can be found if you go to your python location (where python.exe is) and navigate to the Lib\site-packages\cx_Freeze\samples\advanced location where you should find a script called setup.py, take a look at it, your answer should be there.

The exe in Cx_Freeze have dependencies. By copying the exe you are only copying part of the program.




回答2:


A program created by cx_Freeze isn't a single exe file. It's the entire folder created under the build folder. If you just copy the exe file, you are only copying part of the program.

Instead of trying to have two exe files in the same folder, what you should do is have two folders, each being a complete cx_Freeze program. Your subprocess call should be calling ../program2/program2.exe instead of just ./program2.exe.



来源:https://stackoverflow.com/questions/45360513/cx-freeze-how-do-i-convert-multiple-files-into-the-build-folder

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