My python script saves a file in parent of file path:
desktop = os.path.dirname(os.path.realpath(__file__))
desktop = os.path.abspath(os.path.join(desktop, os.pardir))
file_path = desktop + "\\" + "text1.txt"
fo = open(file_path, "wb")
fo.write("blabla")
fo.close()
When I turn this python script into exe using py2exe, the path file_path
cannot be found. How to prevent this?
You have to run py2exe from the place of the modules you are transforming to executables.
edit: more exactly make sure you have your setup.py in that place and run it from there.
I have found the solution here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.