Reputation: 87
I'm a Mac user. I'm trying to load a .gpx file on python,using the following code:
import gpxpy
import gpxpy.gpx
gpx_file = open('Downloads/UAQjXL9WRKY.gpx', 'r')
And I get the following message:
FileNotFoundError: [Errno 2] No such file or directory: 'Downloads/UAQjXL9WRKY.gpx'
Could someone help me figure out why? Thanks in advance.
Upvotes: 0
Views: 577
Reputation: 6776
Obviously, one reason would be that the file does not, in fact, exist, but let us assume that it does.
A relative filename (i.e, one that does not start with a /
) is interpreted relative to the current working direcory of the process. You are apparently expecting that to be the user's home directory, and you are apparently wrong.
One way around this would be to explicitly add the user's home directory to the filename:
import os
home = os.path.expanduser('~')
absfn = os.path.join(home, 'Downloads/whatever.gpx')
gpx_file = open(absfn, ...)
Upvotes: 1