I am currently trying to get a Python program to autostart on my Raspberry Pi. The problem is, that the program is reading in a config file, which is located in the same folder as the program itself. So when I run the Program from IDE, it works fine.
If I try to run it from the console (or rc.local) it doesn't find the config file. If I cd into the folder and try to run it, it works fine again.
So how can I tell Python or rc.local to run from inside the folder? I have tried to goolge for a solution, but couldn't find one.
I don't want to adress the config file with it's complete path, because I program and debug on my PC, but use the program on the raspberry, so I would have to change the path every time I switch between devices.
Hopefully someone can help me, thanks in advance.
I see several possible approaches here:
cd
to the correct directory before running the python program: cd <destination dir> && python your_program.py
, or write a two-line shell script to to this.gethostname()
or by setting an environment variable as shown here).