I am working on code that uses os.walk to search through a relative path. When I run it as a python script I have no problems but after converting it to an exe it can’t seem to find the relative path. The current path prints fine Below is the current solution that i have been working on.
if getattr(sys, 'frozen', False): currentPath = os.path.dirname(sys.executable) relativePath = os.path.join(currentPath,'/../../folder') else: currentPath = inspect.stack()[0][1] relativePath = os.path.join(currentPath,'/../../folder')
for root, dirs, files in os.walk(relativePath):
When hardcoding the relativePath the exe works.
relativePath = “D:/location/../../folder”
Is there something tricky with joining when converting to an exe that I’m missing?
I’m not sure but the cause could be that you are mixing backslashes and forward slashes in the path.
Try changing the code that creates
relativePathto the following:This should ensure that you are definitely using the correct path separator.