'No such file or directory' error Python for android

3.4k Views Asked by At

I have tried this on both Pydroid 3, and QPython3.


My question is very similar to this question which hasn't received an answer. I have a file saved in my internal storage, with the file path /storage/emulated/0/qpython/projects3/filename.xlsx, but if I run the code

with open(r"/storage/emulated/0/qpython/projects3/filename.xlsx", "rb"):
    ...

...this gives a 'No such file or directory' error.


I tried to find solutions online, such as this discussion, but even running that gives exactly the same error. I have tried the same thing without the r, and with // instead of /, but this has not changed anything. There doesn't appear to be any such question on stackoverflow with any answer that works. I am able to run the code perfectly fine on my PC, but I am struggling to get my phone to find the file path.

2

There are 2 best solutions below

1
Ryan On

https://learning-python.com/cgi/showcode.py?name=android-tkinter/CODE/_openbrowser.py

Take away the with.

f  = open("names.txt", "r").read()

for line in f.split("\n"):

    print(line)
0
Roju On

Do this:

import os
os.chdir("/storage/emulated/0")
with open("/qpython/projects3/filename.xlsx", "rb"):