'pyinstaller' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# 'pyinstaller' is not recognized as an internal or external command

The error "'pyinstaller' is not recognized as an internal or external command, operable program or batch file" occurs for 2 main reasons:

  1. Using the pyinstaller module without having it installed.
  2. Not having Python in your user's PATH environment variable.

pyinstaller is not recognized as internal or external command

Make sure you have pyinstaller installed by running the following command in cmd.

cmd
pip install pyinstaller # ๐Ÿ‘‡๏ธ for Python 3 pip3 install pyinstaller # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install pyinstaller # ๐Ÿ‘‡๏ธ using py alias py -m pip install pyinstaller # ๐Ÿ‘‡๏ธ for Python 3 python3 -m pip install pyinstaller # ๐Ÿ‘‡๏ธ If you get a permissions error pip install pyinstaller --user

You should now be able to use the pyinstaller command as follows.

cmd
pyinstaller your_program.py python -m pyinstaller your_program.py py -m pyinstaller your_program.py python 3 -m pyinstaller your_program.py

using pyinstaller

If the installation command doesn't succeed, try running CMD as an administrator.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

You can also try to upgrade the package with the --upgrade option.

shell
python -m pip install pyinstaller --upgrade py -m pip install pyinstaller --upgrade python3 -m pip install pyinstaller --upgrade

Alternatively, you can install the pyinstaller module in a virtual environment:

  1. Open the root directory of your project.
  2. Press Shift and right-click in Explorer.

windows open powershell window here

  1. Click on "Open PowerShell window here".
  2. Run the following commands.
PowerShell
# ๐Ÿ‘‡๏ธ might also be: "python3 -m venv venv" python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ install pyinstaller in the virtual environment pip install pyinstaller

If the python -m venv venv command doesn't work, try the following 2 commands:

  • py -m venv venv.
  • python3 -m venv venv

If you see an error message that "ps1 cannot be loaded because running scripts is disabled on this system", run the following command, type "yes" when prompted and rerun the activation command.

PowerShell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
You can verify that the pyinstaller module is installed by using the pip show pyinstaller command.
PowerShell
pip show pyinstaller pip3 show pyinstaller python -m pip show pyinstaller py -m pip show pyinstaller python3 -m pip show pyinstaller

The pip show pyinstaller command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.

If the error persists, you have to add Python to your user's PATH environment variable.

# Add Python to your user's PATH environment variable

To add Python to your user's PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "User variables for YOUR_USER" section, select the "Path" variable and click "Edit".

select user path click edit

  1. Click on "New" and then click "Browse".

click new browse

  1. You can use one of the following commands to check where your Python installation is located.
cmd
python -c "import os, sys; print(os.path.dirname(sys.executable))" where python

find python path

For me, the path is the following.

cmd
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310

Note that I have Python 3.10 installed, which is reflected in the PATH.

  1. Add the path to Python and then add the path to the Scripts directory that is located in your Python3X folder. This is where the executable files are located.

For me, it is the following path.

cmd
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python310\Scripts

add scripts folder

  1. Once the two paths are added, confirm the changes by clicking on the "OK" button twice.

added python and pip to path

  1. Close your Command prompt application and then reopen it.
Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

If you still encounter issues, try to add Python to your PATH using the official installer.

  1. Download the installer from the official python.org website.

  2. If you have Python already installed, start the installer and click on "Modify".

click modify

You can leave the optional features ticked.

optional features

  1. On the "Advanced Options" screen, make sure to tick the "Add Python to environment variables" option.

add python to environment variables

  1. Once the "Add Python to environment variables" checkbox is checked, click "Install".
Now your Python installation should be set up correctly and Python should be added to your user's PATH environment variable.

If that didn't work, your Python installation might be corrupted.

Start the installer again and click on "Uninstall".

uninstall python

Now that you don't have Python installed on your machine, start the installer again and make sure to tick the "Add python.exe to PATH" option.

add python exe to path

The checkbox won't be checked by default.

Once the "Add python.exe to PATH" checkbox is checked, click on "Install Now".

After the installation, Python will be installed and configured properly.

# Conclusion

To solve the error "'pyinstaller' is not recognized as an internal or external command, operable program or batch file", make sure:

  1. You have the pyinstaller module installed before using it.
  2. You have Python in your user's PATH environment variable.
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev