I have a python script that is supposed to search through a directory and then copy a set list of files into a folder that is created in the same drive the script was run in. (ie. If I run the python script in C:\Users\USER_NAME\Documents then the created folder should also be in that directory). I want to be able to create the executable from the python script and then be able to move it to any directory on the computer and have it run correctly. The issue I am having is that as soon as I turn the python script into an executable using pyinstaller --onefile FILE_NAME.py the folder no longer gets created correctly, and instead gets created as a corrupted file of some sorts. Image of the file that is created. Here is my code that is supposed to create the folder based on a name taken in from a GUI. Again, this works when ran from an IDE, but not as an executable:
dir = os.path.dirname(os.path.realpath(__file__)) + "\\" + values['folderName']
if not os.path.exists(dir):
os.makedirs(dir)
I have tried using this if statement to check whether or not the file is an executable and then assign it the path based on the command sys.executable but this also results in the same problem.
if getattr(sys, 'frozen', False):
dir = sys.executable
Has anyone dealt with this issue and knows how to fix it?