TechTorch

Location:HOME > Technology > content

Technology

How to Create an EXE File in Ubuntu Using Python and PyInstaller

March 05, 2025Technology3196
How to Create an EXE File in Ubuntu Using Python and PyInstaller Devel

How to Create an EXE File in Ubuntu Using Python and PyInstaller

Developing applications and want to distribute them on Windows platforms from your Ubuntu environment? This article guides you on creating a Windows executable (.exe) file from a Python script using PyInstaller in Ubuntu without needing a Windows machine.

Introduction

If you are working on a Python project and plan to deploy it on Windows machines, one of the challenges is packaging the Python script into a standalone .exe file. Traditionally, this requires a Windows environment. However, with the help of WINE and PyInstaller, you can achieve this on any Linux system such as Ubuntu.

Setting Up Python in Ubuntu with WINE

Install Python with WINE: Start by downloading and installing the appropriate version of Python for Windows using WINE on your Ubuntu system. For example, Python 3.8.8 works well with WINE 6.0 on Ubuntu 22.04.

wine python-3.8.8rc1-amd64.exe

Install PyInstaller: Next, you need to install PyInstaller, which is a package converter for Python. You can do this by running the following command in your terminal:

pip install pyinstaller

Steps to Convert .py to .exe

Set Up Environment Variables: Add your Python directory path to the PATH system variable in Ubuntu. This can be done through the terminal:

Open System Settings -> Advanced System Settings -> Environment Variables.

Add the Python directory to the PATH variable.

Open Command Prompt in Script Directory: Use the terminal to navigate to the folder containing your Python script, then open a command prompt in that directory by right-clicking and selecting "Open terminal here."

Compile the Python Script: Run the following command to compile your Python script into an .exe file:

pyinstaller your_script_

Locate the EXE File: After the compilation process is complete, navigate to the dist folder within the PyInstaller directory. You will find your .exe file there.

Alternative Tools: pypy

While PyInstaller is a popular choice, there are alternative tools like pypy that can also be used to create Python .exe files. pypy is a fast, alternative implementation of the Python programming language which can be used to create native binaries.

Conclusion

Creating a .exe file in Ubuntu for a Python application is straightforward with tools like PyInstaller. By leveraging WINE and the right command-line tools, you can distribute your Python scripts on Windows without the need for a Windows environment. This method also enables you to maintain a consistent development workflow across different operating systems.

Keywords:

Python EXE PyInstaller Ubuntu Packaging Python Applications