自动py-to-to-exe/pyinstaller base_library错误
我刚刚完成了一个项目,需要将其转换为可执行文件。我使用自动py-to-exe,它为pyinstaller添加了一个不错的UI,使我的工作更容易。问题在于我的脚本正在使用位于同一目录中的TXT文件(ex:os.path.join(sys.path [0],“ file.txt”)
),只是添加<代码> - add-data c:/path/to/file.txt; 。由于我得到“脚本中的“未经例外”)错误,似乎无法正常工作。这是完整的错误消息:
File "GUI.py", line 141, in <module>
frame = MyFrame()
File "GUI.py", line 40, in __init__
with open(os.path.join(sys.path[0],"file.txt")) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\path\to\\\base_library.zip\\file.txt'
关于如何解决此问题的任何想法?(我必须将其评为代码)
I just finished a project and I need to convert it to a executable file.I'm using auto-py-to-exe which adds a nice UI to pyinstaller so it makes my work easier. The problem is that my scripts are using txt files located in the same directory(ex:os.path.join(sys.path[0],"file.txt")
) and just adding by --add-data C:/path/to/file.txt;
. doesn't seem to work as I get a "Unhandled exception in script" error. This is the full error message:
File "GUI.py", line 141, in <module>
frame = MyFrame()
File "GUI.py", line 40, in __init__
with open(os.path.join(sys.path[0],"file.txt")) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\path\to\\\base_library.zip\\file.txt'
Any ideas on how to solve this problem?(I had to comment it as code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚找到了该解决方案,所以我将其发布给任何寻找它的人:似乎当前目录\ current directory \ base_library.zip sys.path [0]将返回该目录而不是可执行文件的目录(类似于类似的目录独立的 - file .exe,相同的解决方案)。该解决方案只是用来替换sys.path [0] sys.path [0])。替换('\ base_library.zip',''),它将允许脚本再次加速当前目录。
Just found the solution so I'm posting it for anyone looking for it:seems like the current directory becomes \current directory\base_library.zip so sys.path[0] will return that instead of the directory the executable resides(something similar for the standalone --onefile .exe,same solution).The solution is simply to replace sys.path[0] with sys.path[0]).replace('\base_library.zip',''),which will allow the script to acces the current directory again.
此问题的原因是以下行:
或者
sys.path [0] ...
我将其删除,一切正常。
The cause of this problem is the line below:
Or maybe
sys.path[0]...
I removed it, and everything worked fine.
我遇到了同样的问题,但通过更改解决了
:
I had the same issue, but solved it by changing:
with