how to install pyinstaller

How to Install Pyinstaller: A Step-by-Step Guide

By Melissa Jones
AD

Ever needed to convert your Python scripts into standalone executables? That's where PyInstaller, a powerful Python` `wrapper, comes into the picture. This comprehensive guide walks you through the process of installing and using PyInstaller, making your Python applications accessible to anyone without requiring them to have Python or any dependencies installed.

Before we dive into installation and usage, let's set the stage. PyInstaller supports Python standalone executables on Linux, Windows, and macOS, and it works with both Python interpreters (CPython and IronPython) and binary extensions. It also handles scripts with complex dependencies, making it a robust tool for packaging your Python projects.

Installing PyInstaller on Different Operating Systems

PyInstaller installation differs based on your operating system. We'll cover the three major platforms here: Linux, Windows, and macOS.

AD
How to install pip - The Tech Edvocate
How to install pip - The Tech Edvocate
How to install PIP on Windows
How to install PIP on Windows
Secure Python Packages Built From Source | ActiveState
Secure Python Packages Built From Source | ActiveState

Regardless of your OS, ensure you have pip, Python's package manager, installed. If not, you can get it using the following command (assuming you have Python 3 installed):

pip3 install --upgrade pip

Linux

You can install PyInstaller using pip on Linux. Open your terminal and type the following command:

Pip Install a Specific Version: A Guide | Built In
Pip Install a Specific Version: A Guide | Built In
How To Install and Configure Putty SSH Client on Linux Desktop
How To Install and Configure Putty SSH Client on Linux Desktop
pip3 install pyinstaller

Once complete, verify the installation by running

pyinstaller --version

If everything is set up correctly, you should see the installed PyInstaller version.

AD

Windows

For Windows users, we'll use pip as well. Open your Command Prompt (or PowerShell) and execute:

pip install pyinstaller

Afterward, validate the installation by running

pyinstaller --version

You should be greeted with the installed PyInstaller version.

AD

macOS

On macOS, PyInstaller can be installed via Homebrew or pip. If you haven't installed Homebrew yet, you can do so with:

sh -c "$(curl -fsSL `https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh`)"

Once Homebrew is installed, you can fetch PyInstaller using:

brew install pyinstaller

Alternatively, you can install it via pip with:

AD
pip3 install pyinstaller

Verify the installation with

pyinstaller --version

Verifying PyInstaller Installation

Regardless of your OS, ensure that you've correctly installed PyInstaller by running a simple command to generate a simple executable. Let's create a 'hello world' script and turn it into an executable.

Create a new Python file, say `hello.py`, and add the following content:

  1. # hello.py
  2. print("Hello, World!")

Once you've saved the file, navigate to the directory containing it in your terminal. Now, use PyInstaller to generate a single file executable:

pyinstaller --onefile --windowed hello.py

PyInstaller will create a 'dist' directory containing your packaged executable. The `--onefile` option packs your script into a single executable, while `windowed` suppresses the console window when running the final executable on Windows.

Experimentation with the above commands should provide ample confirmation of your PyInstaller installation's success.

You're now ready to create standalone executables from your Python scripts, making it easier to share your creations with others. Stay curious, and happy coding!

AD