Solving PyInstaller FileNotFoundError: [Errno 2] No such file or directory

PyInstaller FileNotFoundError: [Errno 2] No such file or directory is an error which tries to export a python script to .exe using PyInstaller.

This post is a guide showing you why you are having this error and how you can get rid of it in the most efficient way possible, I will also include some alternative solutions that may help you.

Explaining the Error : PyInstaller FileNotFoundError: [Errno 2] No such file or directory

The error can happen to anyone trying to export a python script to .exe using PyInstaller.

The error you are having should be very similar to the error bellow. Make sure you are not trying to solve your error by using fixes that are meant for another problem.

Solving PyInstaller FileNotFoundError [Errno 2] No such file or directory-problem-banner

First, if you are getting the error this means you are

Solution 1 : use a spec file.

The first solution is to generate a spec file.

You can do that by running the command bellow.

Solving PyInstaller FileNotFoundError [Errno 2] No such file or directory-problem-banner-1

The second step is to update the spec file by adding the .ui file to the data section.

Solving PyInstaller FileNotFoundError [Errno 2] No such file or directory-problem-banner-2

The last step is to update the current directory in the Python file.

You should include os.chdir(sys._MEIPASS) in your file like in the example bellow.

Solving PyInstaller FileNotFoundError [Errno 2] No such file or directory-problem-banner-3

Solution 2 : use uic.loadUi().

The second solution is to use

Solving PyInstaller FileNotFoundError [Errno 2] No such file or directory-problem-banner-4

with pyinstaller, you should also keep the r prefix so that the backslashes are interpreted literally.

The solutions above should be enough to solve the problem, if you like our effort make sure to consider donating to our Kofi account, there is a red button that you can use if you are feeling generous.

Summing-up

I can not find any other solution to the problem guys, I tried my best, I hope the above solutions worked for you and the error PyInstaller FileNotFoundError: [Errno 2] No such file or directory is gone.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/