mikiper98
Posts: 10
Joined: Fri Apr 12, 2019 8:59 am

Can't start an executable python program

Fri Oct 25, 2019 8:34 am

So, I want to start off by saying i'm sorry if i'm posting this in the wrong section.
Basically i have a python program that includes tkinter, reading and writing from txt files and ecc... , i want to start it in autostart, but it didn't work, i tried everything i found online and didn't worked so now i tried to open it in the terminal using:

Code: Select all

/home/pi/Desktop/Program.py
and gave me this error

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Desktop/Program.py", line 11, in <module>
    w=open("file.txt","r+")
IOError: [Errno 2] No such file or directory: 'file.txt'
file.txt is a file that i need to open to access some data, the thing that i don't understand is that if i run my program with:

Code: Select all

python Program.py
it works without any problem.
Do you know why this happends or you guys know a way around this issue?
Thanks
Last edited by mikiper98 on Fri Oct 25, 2019 8:40 am, edited 1 time in total.

User avatar
neilgl
Posts: 2224
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Can't start an executable python program

Fri Oct 25, 2019 8:39 am

Which directory is file.txt in?
Also that post talks about Prova.py ?

jahboater
Posts: 5824
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Can't start an executable python program

Fri Oct 25, 2019 8:41 am

Looks like you are running the program in two different places.
When you open the file, you should give it the full path such as "/home/pi/Desktop/file.txt".
The environment variable $HOME may be useful unless you are starting it from /etc/rc.local or cron.

mikiper98
Posts: 10
Joined: Fri Apr 12, 2019 8:59 am

Re: Can't start an executable python program

Fri Oct 25, 2019 8:42 am

neilgl wrote:
Fri Oct 25, 2019 8:39 am
Which directory is file.txt in?
Also that post talks about Prova.py ?
file.txt is still in the Desktop folder, the same as Program.py
Prova.py was a typo sorry :D

mikiper98
Posts: 10
Joined: Fri Apr 12, 2019 8:59 am

Re: Can't start an executable python program

Fri Oct 25, 2019 8:52 am

jahboater wrote:
Fri Oct 25, 2019 8:41 am
Looks like you are running the program in two different places.
When you open the file, you should give it the full path such as "/home/pi/Desktop/file.txt".
The environment variable $HOME may be useful unless you are starting it from /etc/rc.local or cron.
It works!!!!
It was easier than expected... i would never think about that thank you!

Return to “Troubleshooting”