[PyInstaller]Make Python an executable file



PyInstaller can be used to convert a program created with python into an executable file (.exe).
There are other tools that can be converted into executable files, but PyInstaller is recommended because it is fairly easy to use.


  • Windows 10
  • Python 3.6.2
  • PyInstaller 3.5


Easy installation with pip.

pip install pyinstaller

Execution method

Build (convert .py file to .exe file) with the following command. Options are not always necessary.

pyinstaller .\main.py --onefile --noconsole --clean
  • --onefile It is output as one EXE file. If this is not specified, the output is divided into multiple files.
  • --noconsole The console is not opened when the created EXE file is executed. If this is not specified, the console will open when the EXE file is executed.
  • --clean Before building, delete the temporary files remaining after the previous build.

When the build is complete, the dist folder is created in the current folder. An EXE file should be created in it.

The created EXE file will work even if it is moved to another folder.
Note that if you specify an external file with a relative path in the program, it may not work.

Precautions when running the created executable file on another PC

You may need to be careful when you run the created EXE file on another PC.

・Match the platform

If you make it an executable file with 64-bit Python, even if you bring the created EXE file to a 32-bit PC, it will not work.
In such a case, install 32-bit Python in your environment and run PyInstaller.

Of course, you can’t even run something made on Windows on Linux. If you want to run on Windows, run PyInstaller on Windows. If you want to run on Linux, run PyInstaller on Linux.

・Referencing external files

If you are referring to an external file from a program, make sure that the file is on your PC. If you are referring to a file that is on this PC but not on that PC, it may stop working.

However, you can also include an external file in the executable file. Please refer to the following.

At the end

With a single command, there is no need to prepare a configuration file, and you can easily make a Python file into an executable file.
I am dissatisfied that the execution is a little slow, but I think that this is enough when you want to make an EXE file for the time being.

Related Posts