-1

I create a python script that outputs the result in a text file and it works, but when I convert it to exe file, it doesn't create the the textfile.

myfile = open("Mental abilities.txt", "w", encoding="UTF-8")
#any codes
myfile.close()

I used pyinstaller and auto-py-to-exe to covent python script to exe file.

  • Are you looking in the right directory for the file? – John Gordon Dec 26 '21 at 21:50
  • Did you configure your `pyinstaller` script to include that file? `Pyinstaller` doesn't know you need it unless you tell it. You might consider just embedding it in the Python code to avoid that problem. – Tim Roberts Dec 26 '21 at 21:55
  • 1
    when you run a converted exe, the python file that is trying to access that file is not located in the same directory as the exe, you can take a look at [this](https://stackoverflow.com/a/70465334/14531062) to see how to create a path or just embed it in the exe if that is possible (if you don't intend on changing that file externally) – Matiiss Dec 26 '21 at 22:08
  • @JohnGordon yes I am looking in the right directory – علاء الغرابلى Dec 26 '21 at 22:10
  • 1
    I can tell you with quite some certainty that you are not looking in the right directory when it is converted to an exe – Matiiss Dec 26 '21 at 22:12
  • Does this answer your question? [Determining application path in a Python EXE generated by pyInstaller](https://stackoverflow.com/questions/404744/determining-application-path-in-a-python-exe-generated-by-pyinstaller) – CrazyChucky Dec 26 '21 at 22:46

1 Answers1

-1

the problem is solved by add python scripts to the path of Environment variables