FileNotFoundError: [Errno 2] No such file or directory

38 views
Skip to first unread message

Tom Large

unread,
Nov 14, 2020, 8:40:28 AM11/14/20
to PyInstaller
Hi, 
first I'm sorry to disturb you.
I have an issue concerning my app. 
I'm on Mac, python 3.7, using pyinstaller/auto-py-to-exe.
I"m able to convert it into an exec, it works fine. except one thing.
i have multiple files in my project. In fact I made a sneakers bot. so I have like 6 python script. and also config.json, profils.csv, proxies.txt....
All is working, it includes well my python script. except config.json, profils.csv....
in my script: 
f = open('Config.json', 'r')...
but I get this error:

FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/mf/m76x8ty92_s62ly5dyfrmhm80000gn/T/_MEIOZO6HY/Config.json'

I don't understand why it is looking for this path. 

Could you help me please ? 

bwoodsend

unread,
Nov 14, 2020, 11:17:34 AM11/14/20
to PyInstaller

You need to read up on what --onefile actually does to understand why it’s looking in such an obscure corner of your PC.

PyInstaller doesn’t collect data files by default - you need to use the --add-data option to explicitly add each one (note the very specific syntax --add-data=./Config.json:.). You also should read up on using __file__ to locate data files at run time. Your code would break even without PyInstaller if you ran it from a different directory. Once you’ve done that you can then see the docs for using __file__ in PyInstaller.

Reply all
Reply to author
Forward
0 new messages