If you want to run a Python program on a Windows system without installing Python, you can convert it into a standalone EXE file using PyInstaller.
PyInstaller bundles a Python application and all its dependencies into a single package, including the Python interpreter.
Prerequisites:
- Python installed on your system
- pip package manager
- Windows OS
Here are the steps to convert your Python script into a .exe file using PyInstaller:
- Install PyInstaller: You can install PyInstaller using pip, the Python package manager. Open your command prompt or terminal and run the following command:
Bash
pip install pyinstaller- Navigate to Your Script Directory: Using the command prompt or terminal, navigate to the directory where your Python script (example :
example.py) is located. - Create the .exe File: Once you’re in the directory containing your script, you can create the .exe file using PyInstaller. Run the following command:
Bash
pyinstaller --onefile example.py- Replace
example.pywith the name of your Python script. - Locate the .exe File: After PyInstaller finishes its work, you can find the standalone executable file in the
distdirectory within your script’s directory.
That’s it! You should now have a standalone .exe file that you can run on any Windows machine without needing Python installed.
⚠️ Common Issues
- Antivirus may flag the EXE as suspicious (false positive)
- Large file size after conversion
- Missing DLL errors on older systems
Frequently Asked Questions
❓ Does the EXE work on other computers?
Yes, the generated EXE can run on Windows systems without Python installed.
❓ Can I convert GUI Python scripts?
Yes, PyInstaller supports GUI applications built with Tkinter, PyQt, and others.
