There are a lot of methods to get the path of a script in Python, but the following method always work, even you use py2exe or PyInstaller to compile the script to binary executable file.
1 2 3 4 5 6
Note there is a big difference between the path of the script and the current path, ie the “.” path in Windows and POSIX systems. When you run the script from other folder, such like this:
Then the current folder is /home/leon/, while the path of the script is /home/leon/bin.