1

I am trying to print the directory of the .py file however I want to run the file from another directory by adding the file's directory to the system Path file. I ran in to some problems when I turned to file to an executable with pyinstaller.

The code in the file:

import pathlib

path= pathlib.Path(__file__).parent.resolve()

print(path)

Let's say the directory of the file is: C:\Users\User\Documents\file.py

And let's say the current working directory is: C:\Users\User

When I run file.py I get: C:\Users\User\Documents which is the output I want

When I run file.exe I get: C:\Users\User which is not what I wan't

I don't understand why the .py and .exe files are working differently. What can I do to fix the problem? I tried a bunch of stuff from here but none of them seem to work: How do I get the full path of the current file's directory?

0 Answers0