How to Fix ‘zsh: command not found: jupyter’ Error After Installing Jupyter with pip

You just installed Jupyter using pip and tried running it, only to get the frustrating 'zsh: command not found: jupyter' error. Now Jupyter won’t launch, even though you installed it!

Not to worry – this is a common issue caused by pip not adding Jupyter to your system PATH properly. The good news is it can be fixed with a few easy steps to get Jupyter running smoothly again.

In this guide you’ll learn:

  • What causes the ‘command not found’ error after pip install
  • How to add pip installed packages like Jupyter to your PATH
  • Extra steps for fixing this issue on Mac zsh and Linux
  • Verifying the fix and successfully launching Jupyter

Let’s dig in and banish that pesky ‘zsh command not found’ issue for good!

What Causes the Jupyter ‘Command Not Found’ Error?

When you install a package using pip, it downloads and unpacks the files to your Python packages folder (usually ~/python/lib/pythonX.X/site-packages).

However, this does not automatically add the package executable to your shell’s PATH environment variable. The PATH controls where your shell looks for executables when you try to run commands.

So when you attempt to launch Jupyter, your zsh shell searches the PATH but can’t find the jupyter command you’re asking it to run, resulting in the ‘command not found’ error.

To fix this, you need to modify your PATH to include the folder where pip installed Jupyter so it will be found.

How to Add Pip Packages Like Jupyter to Your PATH

To avoid ‘command not found’ errors, your PATH needs to include the path where pip packages containing executables are installed.

Here are the steps to add pip package executables to your PATH on macOS and Linux:

1. Find Your Site Packages Folder

First, find where your Python site packages folder is located. The default is in your home folder:

~/.local/lib/pythonX.X/site-packages

Or if using a virtual environment it will be under your venv path instead:

venv_path/lib/pythonX.X/site-packages

Replace X.X with your Python version.

2. Export the Site Packages Path to Your PATH

Next, you need to export this site packages path to be included in your shell’s PATH.

For bash or zsh on macOS/Linux, add this to your ~/.bash_profile or ~/.zshrc config file:

export PATH="$HOME/.local/lib/pythonX.X/site-packages:$PATH"

Or for a venv:

export PATH="venv_path/lib/pythonX.X/site-packages:$PATH"

For fish shell on Linux/macOS, use:

set -U fish_user_paths ~/.local/lib/pythonX.X/site-packages $fish_user_paths

On Windows, add it through Advanced System Settings instead.

3. Reload Your Shell

After adding the new PATH export, reload your shell to apply the changes.

On Linux/macOS:

source ~/.bash_profile

Or for zsh:

source ~/.zshrc

On Windows, restart the cmd or Powershell session.

Once reloaded, the pip packages folder will now be included in your PATH when running commands!

Extra Fixes for Zsh on Mac

Sometimes setting the PATH as above doesn’t fix the issue on Mac with zsh. A couple extra steps may be needed:

Add .local/bin

Zsh on Mac may look for executables in .local/bin rather than site-packages. Try also adding this folder to your PATH in .zshrc:

export PATH="$HOME/.local/bin:$PATH"

You can also manually create a symlink from .local/bin to the site-packages folder:

ln -s ~/.local/lib/pythonX.X/site-packages ~/.local/bin

Now zsh will search .local/bin and find the symlinked packages.

Verifying the Fix and Launching Jupyter

Once you’ve updated your PATH, verify that the fix worked and you can now run Jupyter!

Check the PATH

First, echo your PATH to confirm it contains the expected folders:

echo $PATH

You should see your ~/.local/lib/pythonX.X/site-packages or venv path included.

Try Launching Jupyter

Then attempt to run the jupyter command again in your shell:

jupyter notebook

Jupyter should launch successfully without any ‘command not found’ issues!

Fixing this is essential to be able to run Jupyter and other pip-installed packages from the command line. Now you know how to update your shell’s PATH to include pip package executables. No more pesky ‘command not found’ problems!

Leave a Comment