Error executing Jupyter command 'notebook': [Errno 2] No such file or directory

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
4 min

banner

# Error executing Jupyter command 'notebook': [Errno 2] No such file or directory

The "Error executing Jupyter command 'notebook': [Errno 2] No such file or directory" most commonly occurs on Linux distributions, e.g. Ubuntu or Arch.

The error occurs for multiple reasons:

  1. Having a corrupted installation of Jupyter Notebook.
  2. Your installation of Jupyter Notebook clashing with another module, e.g. IPython.
  3. Using an incorrect alias of the jupyter notebook command.

# Jupyter clashes with IPython

The jupyter notebook command sometimes clashes with the IPython module.

The first thing you should try is to uninstall IPython.

shell
# ๐Ÿ‘‡๏ธ Uninstall the IPython module sudo apt remove ipython sudo apt purge ipython sudo apt autoremove # ๐Ÿ‘‡๏ธ Install the Jupyter module pip install jupyter # ๐Ÿ‘‡๏ธ Or with pip3 pip install jupyter

uninstall ipython module

Try to issue the jupyter notebook command after uninstalling IPython.

shell
jupyter notebook

# Reinstall the Jupyter module on your machine

Make sure you have the python-dev package installed if you are on Linux.

shell
# ๐Ÿ‘‡๏ธ For Debian (Ubuntu) sudo apt install python3-pip python3-dev # ๐Ÿ‘‡๏ธ For Redhat / CentOS sudo yum install python3-devel # ๐Ÿ‘‡๏ธ For Alpine Linux sudo apk add python3-dev # ๐Ÿ‘‡๏ธ For openSUSE sudo zypper in python3-devel # ๐Ÿ‘‡๏ธ For Cygwin apt-cyg install python3-devel

install python3 dev and pip

Now, reinstall the jupyter module using the --force-reinstall option.

shell
# for python 2 pip install --upgrade --force-reinstall --no-cache-dir jupyter # for python 3 pip3 install --upgrade --force-reinstall --no-cache-dir jupyter

pip reinstall jupyter

You can read more about pip's --no-cache-dir option in the following article.

If you get a permissions error when running the command, add the --user option.

shell
# For python 2 pip install --user --upgrade --force-reinstall --no-cache-dir jupyter # For python 3 pip3 install --user --upgrade --force-reinstall --no-cache-dir jupyter

If you still get a permissions error, try prefixing the command with sudo.

shell
# For python 2 sudo pip install --upgrade --force-reinstall --no-cache-dir jupyter # For python 3 sudo pip3 install --upgrade --force-reinstall --no-cache-dir jupyter

Try to issue the jupyter notebook command after uninstalling IPython.

shell
jupyter notebook

After you issue the command, the server should start and you should see the Notebook app in your browser.

jupyter start development server

# Try the other variations of the jupyter notebook command

The jupyter notebook command sometimes changes to a different alias after installation.

Try running the following command instead.

shell
jupyter-notebook

using jupyter notebook alias command

Notice that the words are separated by a hyphen.

If the command doesn't start the server, try using the python -m notebook command instead.

shell
python -m notebook # Or python3 python3 -m notebook

using python m notebook command

If the python -m notebook command words, use the export command to update your PATH environment variable.

shell
export PATH=$PATH:~/.local/bin/

update path environment variable

Make sure to restart your terminal after using the export command for the changes to take effect.

After you've restarted your terminal, try issuing the jupyter notebook command.

shell
jupyter notebook

# Install Jupyter using the apt packaging tool

If the error persists, try installing jupyter using apt.

shell
# Update packages sudo apt update # Install pip and Python sudo apt install python3-pip python3-dev # Upgrade pip sudo -H pip3 install --upgrade pip # Install jupyter-notebook sudo apt install jupyter-notebook

install jupyter notebook using apt

After running the sudo apt install jupyter-notebook, try issuing the jupyter notebook command.

shell
jupyter notebook

# Install the Jupyter module using the correct pip version

If the error persists, get your Python version and make sure you are installing the package using the correct Python version.

shell
python --version

get python version

For example, my Python version is 3.11.2, so I would install the GitPython package with pip3.10 install jupyter.

shell
pip3.11 install --upgrade --force-reinstall --no-cache-dir jupyter

install jupyter notebook using correct pip version

Notice that the version number corresponds to the version of pip I'm using.

If you get a permissions error when running the command, add the --user option.

shell
pip3.11 install --user --upgrade --force-reinstall --no-cache-dir jupyter

If you still get a permissions error, try prefixing the command with sudo.

shell
sudo pip3 install --upgrade --force-reinstall --no-cache-dir jupyter

Try to issue the jupyter notebook command after installing the module with a specific pip version.

shell
jupyter notebook

If the error persists, try using one of the aliases of the jupyter notebook command.

shell
jupyter-notebook

using jupyter notebook alias command

Notice that the words are separated by a hyphen.

If the command doesn't start the server, try using the python -m notebook command instead.

shell
python -m notebook # or python3 python3 -m notebook

using python m notebook command

If the python -m notebook command words, use the export command to update your PATH environment variable.

shell
export PATH=$PATH:~/.local/bin/

update path environment variable

Make sure to restart your terminal after using the export command for the changes to take effect.

After you've restarted your terminal, try issuing the jupyter notebook command.

shell
jupyter notebook

# Conclusion

To solve the "error executing Jupyter command 'notebook': [Errno 2] No such file or directory", reinstall your jupyter module using pip or apt and make sure the IPython module is not installed as it often clashes with jupyter.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

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