gpt4 book ai didi

How to package a large Python project using cxFreeze into a single exe (directory not found error)(如何使用cxFreeze将大型Python项目打包为单个exe(目录未找到错误))

转载 作者:bug小助手 更新时间:2023-10-24 22:17:51 25 4
gpt4 key购买 nike



I'm working on a Python project right now using customtkinter and opencv. This project contains multiple directories with python files inside, all in the src directory. There is also a Data directory and Resources directory that store the current data and he resources needed for the app respectively. In order to make this project easier to distribute and use for the end-user, I am trying to use cxFreeze to freeze the whole thing into a single exe that can be simply run by the user. Here is my project structure:

我现在正在做一个使用Customtkinter和OpenCV的Python项目。该项目包含多个目录,其中都有Python文件,这些文件都在src目录中。还有一个数据目录和资源目录,分别存储应用程序所需的当前数据和资源。为了使这个项目更容易分发和最终用户使用,我正在尝试使用cxFreeze将整个项目冻结到一个可以由用户简单运行的可执行文件中。以下是我的项目结构:


Project Structure


And this is what I have in my setup.py file:

这是我的setup.py文件中的内容:


from cx_Freeze import setup,Executable

include_files = ['QRCodeAttendanceV2', 'src']

options = {
'build.exe': {
'include_files':include_files
}
}

setup(
name="QR Attendance",
version=0.1,
description="A QR-based attendance system utilizing JSON data storage (local)",
executables=[Executable("main.py",base="Win32GUI")],
options=options
)

However, when I run the exe file that is generated by python setup.py build I get this error:
Error Message: src Directory not found

但是,当我运行由python setup.py版本生成的exe文件时,我收到以下错误:


This project also has a virtual environment with all the necessary dependencies installed already

该项目还具有一个虚拟环境,其中已经安装了所有必要的依赖项


Initially, I tried going online for potential solutions to this issue and I saw that the include_files option was used fairly often tominclude a directory, so I added that option to my setup.py file as you can see above but I'm still getting the exact same error. I also tried running the build command from the root directory (QRCodeAttendanceV2) but that didn't work since there's no main.py in the root directory. What is the best way to include all those files into the cxFreeze build?

最初,我试着上网寻找这个问题的潜在解决方案,我看到INCLUDE_FILES选项经常被用来包括一个目录,所以我将该选项添加到我的setup.py文件中,正如您在上面看到的那样,但我仍然收到完全相同的错误。我还尝试从根目录(QRCodeAttendanceV2)运行构建命令,但不起作用,因为根目录中没有main.py。将所有这些文件包含到cxFreeze构建中的最佳方式是什么?


更多回答
优秀答案推荐

After doing some experimentation, the solution to this issue is simply to take the setup.py file and move it outside of the src directory. Once that is done, the exe files runs properly and the program works correctly.
enter image description here

在做了一些实验之后,这个问题的解决方案是简单地获取setup.py文件并将其移动到src目录之外。一旦完成,exe文件正常运行,程序正常工作。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com