执行后,py可执行文件无法找到脚本中包含的导入功能,为什么?

发布于 2025-01-24 13:06:09 字数 1315 浏览 3 评论 0原文

我有一个.py脚本,该脚本会从另一个.py脚本导入某些函数,该脚本位于同一文件夹中的另一个目录中。其中一些脚本从文件夹本身中包含的其他一些.py脚本导入函数。

我已经使用 pyinstaller 。但是,执行时, .exe 应用 ./ dist 文件夹 立即打开并关闭

我试图通过 cmd/k 命令提示中通过 cmd/k 来查找错误,该文件即使在执行后仍保持打开状态显示错误。这就是我得到的:

”在此处输入图像描述”

您可以看到它显示了此错误

filenotfounderror:[errno 2]没有这样的文件或目录:'./static/user.txt'

fyi:这是代码的块哪个从给定的 .txt 文件中读取一些文本(通过VSCODE终端运行时工作正常),但是在这里它无法检测到路径/定位,为什么?

我的CWD 的是这样(下)。 user.txt 文件位于 ./ static (在底部)和.py脚本读取其中一些文本由于某种原因无法完成,而在 .exe 格式中执行。

任何类型的帮助或建议都会有所帮助,谢谢!

I have a .py script which import some functions from an another .py script, located in an another directory in the same folder. And some of those scripts import functions from some other .py scripts contained in the folder itself.

I have created an executable file of my main.py file (which eventually uses functions from all other files) using pyinstaller. However when executed, the .exe application, located in the
./dist folder just opens up and closes immediately.

I tried to find the error by executing the file through cmd /K in Command Prompt, which lets the file to remain open even after executing and show errors. This is what I got :

enter image description here

As you can see it showed this error :

FileNotFoundError: [Errno 2] No such file or directory: './Static/user.txt'

FYI: This is a block of code which reads some text from the given .txt file (works fine when run through VsCode terminal), but here it fails to detect the path / locate it, Why?

The tree of my cwd is like this (below). The user.txt file is located inside the ./Static (at bottom) and the .py script reads some text from it, which it isn't able to do now for some reason, while executed in an .exe format.

enter image description here

Any kind of help or suggestions would be really helpful, Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2025-01-31 13:06:09

您是否使用当前的工作目录(CWD)来定义文本文件的相对路径?

如果是,请从Dist文件夹中删除EXE或在DIST文件夹中放置。/static。

Are you using the current working directory (cwd) to define the relative path of the text file ?

If yes , remove the exe from the dist folder or put ./Static inside the dist folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文