Ubuntu 18.04安装PyInstaller后执行命令提示‘pyinstaller: command not found’求助
Hey there! This is a super common issue when pip installs packages to a directory that isn’t in your system’s default PATH—let’s walk through fixing it step by step.
Step 1: Find where PyInstaller was installed
First, let’s confirm the exact location of your PyInstaller installation. Run this command in your terminal:
pip show pyinstaller
Look for the Location line in the output. It’ll look something like this:
Location: /home/your-username/.local/lib/python3.6/site-packages
The actual pyinstaller executable lives in the bin folder of that parent directory. So in this example, the full path to the command is /home/your-username/.local/bin/pyinstaller.
Step 2: Check if this path is in your system PATH
Next, let’s see if that bin directory is already in your system’s PATH (the list of places your terminal looks for commands). Run:
echo $PATH
Look for the path we found in Step 1 (like /home/your-username/.local/bin). If you don’t see it, that’s exactly why the terminal can’t find pyinstaller.
Step 3: Fix the PATH temporarily (for the current terminal session)
If you just need to use PyInstaller right now, run this command to add the path to your current session’s PATH:
export PATH="$HOME/.local/bin:$PATH"
Now try running pyinstaller myscript.py again—it should work!
Step 4: Fix the PATH permanently (for all future sessions)
To make this fix stick every time you open a terminal, we’ll add the path to your shell configuration file:
- Open your
.bashrcfile with a text editor (we’ll use nano here, it’s simple):nano ~/.bashrc - Scroll to the very bottom of the file and add this line:
export PATH="$HOME/.local/bin:$PATH" - Save the file by pressing
Ctrl+O, hit Enter, then exit nano withCtrl+X. - Make the changes take effect immediately by running:
source ~/.bashrc
Bonus: Double-check your pip/Python version match
Ubuntu 18.04 comes with both Python 2 and Python 3 pre-installed. If you used pip (which defaults to Python 2) but your script uses Python 3, you might have installed PyInstaller for the wrong version. Fix this by installing it with pip3 instead:
pip3 install pyinstaller
Then repeat the steps above if needed (though pip3 will still install to ~/.local/bin in most cases).
内容的提问来源于stack exchange,提问作者afsara_ben

