[英]After using Pyinstaller to convert .py to .exe the program cant find the correct txt file location
I'm currently trying to convert my python program into an executable but when i do convert it and run the .exe file it throws the error, No such file or directory: 'profiles.txt'
. 我目前正在尝试将python程序转换为可执行文件,但是当我将其转换并运行.exe文件时,它将引发错误,
No such file or directory: 'profiles.txt'
。
I'm trying to read and write to the text file based on user input. 我正在尝试根据用户输入读取和写入文本文件。 is there a way i can get my program to find the correct text file so I can get the exe file to work?
有没有办法让我的程序找到正确的文本文件,以便使exe文件正常工作?
If your program depends of other files, you can include it in the program using the Pyinstaller spec files . 如果您的程序依赖于其他文件,则可以使用Pyinstaller spec文件将其包括在程序中。 Spec files contains all the instructions to create your program, including additional data files or missing modules that Pyinstaller cann't find.
规范文件包含创建程序的所有说明,包括Pyinstaller找不到的其他数据文件或缺少的模块。 I strongly recommend you to use it.
我强烈建议您使用它。
A spec file looks like: 规格文件如下所示:
block_cipher = None
a = Analysis(['minimal.py'],
pathex=['/Developer/PItests/minimal'],
binaries=None,
datas=[ ('src/README.txt', 'myfiles') ],
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
excludes=None,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,... )
coll = COLLECT(...)
The files that you need to provide to your program are in datas=
. 您需要提供给程序的文件位于
datas=
。 In this example you will add the file readme.txt
in the folder src
of your pc to the folder myfiles
in the bundled app. 在此示例中,您将把PC文件夹
src
中的文件readme.txt
添加到捆绑应用程序中的myfiles
文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.