Convert python file into exe using auto-py-to-exe

661 Views Asked by At

I have just finished a project where I have made a connect 4 game and am trying to convert it to an exe file using auto-py-to-exe.

I want to use the one-file option, however every time it finishes and I run it, it would come up with an error:

Failed to execute script 'main' due to unhandled exception: No file 'Assets/icon.png' found in working directory '...'

Then in the box it says:

Traceback (most recent call last):
File "main.py", line 32, in <module>
FileNotFoundError: No file 'Assets/window-icon.png' found in working directory '...'.

I've tried quite a few alterations, e.g. not using the image, but then it would come up with the same error but for a different added file.

How can I fix this?


EDIT:
I've tried it again by using the os module and giving the full directories to all the files in main.py, but that hasn't changed anything.

1

There are 1 best solutions below

0
On BEST ANSWER

I was also facing this problem then I got the solutions from analysing other threads.
You have to update your script by adding this function

import sys
import os

def resource_path(relative_path):
     """ Get absolute path to resource, works for dev and for PyInstaller """
    base_path=getattr(sys,'_MEIPASS',os.path.dirname(os.path.abspath(__file__)))
     return os.path.join(base_path, relative_path)

and changing address of every additional files used in your script

for example

icon = resource_path("game.icon")

You just have to use auto-py-to-exe just like shown below

Showing the options you can just use

Add all the files used in the Additional File section of it and make sure that the period(.) is there in the destination
That's it !