执行后,py可执行文件无法找到脚本中包含的导入功能,为什么?
我有一个.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 :
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.
Any kind of help or suggestions would be really helpful, Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用当前的工作目录(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.