Explain Codes LogoExplain Codes Logo

Pip installs packages successfully, but executables not found from command line

python
pip
path-variable
bashrc
Nikita BarsukovbyNikita Barsukov·Mar 2, 2025
TLDR

Often, the issue arises because the installation path for the executables of pip installed packages isn’t in your PATH environment variable. A quick fix:

If you're working on a Windows system:

setx PATH "%PATH%;C:\Users\YourUsername\AppData\Local\Programs\Python\PythonXX\Scripts"

(Change PythonXX to match your Python version)

For Unix-like systems(Linux/macOS):

echo 'export PATH="$PATH:/home/yourusername/.local/bin"' >> ~/.bashrc

(Load the changes with source ~/.bashrc or restart the terminal)

Remember to replace the aforementioned paths with the ones corresponding to your Python installation.

Deciphering PATH variable

The PATH is a list of directories that your operating system searches through when looking for executable files. When pip installs a package that includes executables, they might be stored in a directory missing from your PATH. Therefore, your system cannot access these executables from the command line.

Inspect your current PATH with:

echo $PATH # Hey, my PATH! Fancy seeing you here!

Make sure that the directory where pip places the scripts (usually ~/.local/bin on Unix-like systems) is part of your PATH, if not you need to include it.

Setting PATH the right way

To ensure your changes persist across sessions, add the correct path to your shell configuration file (.bashrc or .bash_profile):

echo 'export PATH="$PATH:/path/to/directory"' >> ~/.bashrc source ~/.bashrc # Knock knock. Who's there? Your updated PATH. BOOM!

For systems with multiple Python versions, make sure you're adding the specific version's bin directory to your PATH:

echo 'export PATH="$PATH:~/.local/bin/python3.X/bin"' >> ~/.bashrc # Python's got versions. You've got options. Winning at life!

Exploring missing executables causes

If your PATH is correctly set and you're still running into issues, several different culprits might be to blame:

  • Multiple Python installations: Double-check you're changing the PATH for the right version. Run which python and check.
  • Custom Python userbase: For installations done using pip install --user, check your user installation directory with Python's site module.
  • Non-default install locations: The location of the executable might not be included in your PATH.

Other ways to fix this

Validate with the ‘which’ command

Use the which command to locate installed executables:

which <executable_name> # Marco! Polo! But for executables.

Check out Python’s user directory

If you're using the --user flag with pip, you can find out the user install directory with:

python -m site --user-base # I always feel like... Python is watching me...

Include /bin for Unix-like systems or \Scripts for Windows when updating PATH.

Reboot your shell

It's essential to restart your terminal or load your updated profile for changes in the PATH to take effect:

source ~/.bash_profile # For macOS source ~/.bashrc # For Unix-like systems

Make PATH adjustments dynamic

If you frequently switch between different Python environments, consider using scripts or tools like pyenv that adjust the PATH on-the-fly.