Python pyInstaller可以';找不到数据文件
我正在尝试使用pyInstaller将python脚本编译成独立的可执行文件 我的脚本包含两个数据文件,分别名为“input.txt”和“output.txt”,这两个文件都可以在脚本的根文件夹中找到 以下是使用这些文件的脚本:Python pyInstaller可以';找不到数据文件,python,pyinstaller,Python,Pyinstaller,我正在尝试使用pyInstaller将python脚本编译成独立的可执行文件 我的脚本包含两个数据文件,分别名为“input.txt”和“output.txt”,这两个文件都可以在脚本的根文件夹中找到 以下是使用这些文件的脚本: input_file = open('input.txt', 'r') output_file = open('output.txt', 'w') 当我在pyCharm中运行它,读取input.txt并编写output.txt时,它工作得非常好 为了使
input_file = open('input.txt', 'r')
output_file = open('output.txt', 'w')
当我在pyCharm中运行它,读取input.txt并编写output.txt时,它工作得非常好
为了使用pyInstaller将其编译为可执行文件,我使用了.spec文件:
a = Analysis(['KHTools.py'],
pathex=['/Users/rafaelcarmo/PycharmProjects/KHTools'],
binaries=[],
datas=[ ('input.txt', '.'), ('output.txt', '.') ],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
这些文件是在可执行文件的根文件夹中创建的,它们甚至包含与原始文件相同的数据,因此我相信这是一个成功的.spec创建
但是,当我运行代码时,我得到一个错误:
Traceback (most recent call last):
File "KHTools.py", line 62, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'
[17561] Failed to execute script KHTools
回溯(最近一次呼叫最后一次):
文件“KHTools.py”,第62行,在
FileNotFoundError:[Errno 2]没有这样的文件或目录:“input.txt”
[17561]无法执行脚本工具
我真的不明白。该文件位于bundle(input.txt)中,其内容与原始文件中的内容相同,并返回此错误
有人知道我做错了什么吗