简体   繁体   中英

Python on MAC - finding data files

I have a Python application built under PyInstaller on a MAC. I do not want to have a terminal window when it is running so I specified the --noconsole option. Apparently, under MACos, this option still provides a console (terminal) window if you use the EXE file. If you use the MAC application package to start, then you do not have the console/terminal window.

The problem is that the program reads a data file at initialization. When I run the EXE, that data file is in the same directory as the EXE and it loads fine. But when it runs as an app, it reads from the default working directory and I have no idea where that is. So it can't find the data file required. And reading further it seems from MAC OS to OS the working directory location might change. I moved the data file where the EXE is in the MAC application, but when Python reads that is not the directory it is reading from.

So how can I place the required data file somewhere the Python application (not running the EXE directly) will find it.

Under Windows, the data file is just in the same directory where the EXE is running and there is no console window. There is no concept of the MAC application type. But if I don't want to have the Terminal window, I need to resolve where to place a data file so that will be found.

I suggest digesting some of these basic Apple macOS developer documents. All your answers will come through understanding these.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM