How to Open Jupyter Notebook from CMD: A Step-by-Step Guide

Jupyter Notebook is an essential tool for data science, machine learning, and Python programming. It provides an interactive computing environment where you can write and execute code, visualize data, and document workflows efficiently. One of the most common questions from beginners is how to open Jupyter Notebook from CMD (Command Prompt).

In this guide, we will cover multiple ways to launch Jupyter Notebook from the command line, troubleshoot common issues, and optimize your workflow for a smooth Jupyter experience.


1. Prerequisites for Opening Jupyter Notebook from CMD

Before opening Jupyter Notebook from the command line, ensure the following requirements are met:

1. Install Python

Jupyter Notebook runs on Python, so you need to have Python installed.

Check if Python is Installed

Open CMD and type:

python --version

If Python is not installed, download and install the latest version from the official Python website.

2. Install Jupyter Notebook

If Jupyter Notebook is not already installed, you can install it using pip:

pip install notebook

Verify the installation:

jupyter notebook --version

3. Set Up a Virtual Environment (Optional but Recommended)

Using a virtual environment prevents dependency conflicts and keeps your workspace organized.

pip install virtualenv

Create and activate a virtual environment:

  • Windows: python -m venv jupyter_env jupyter_env\Scripts\activate
  • Mac/Linux: python -m venv jupyter_env source jupyter_env/bin/activate

After activation, install Jupyter Notebook within the environment:

pip install notebook


2. How to Open Jupyter Notebook from CMD

Method 1: Standard Way to Open Jupyter Notebook

Once Jupyter Notebook is installed, opening it from CMD is simple. Just type:

jupyter notebook

This command will:

  • Start the Jupyter Notebook server.
  • Open Jupyter Notebook in your default web browser.
  • Display a terminal output showing the server log and available notebooks.

Method 2: Open Jupyter Notebook from a Specific Directory

By default, Jupyter Notebook launches in the home directory. To open it in a specific folder, navigate to that directory first using the cd command:

cd path\to\your\folder
jupyter notebook

For example, to open Jupyter Notebook in D:\Projects:

cd D:\Projects
jupyter notebook

Method 3: Open Jupyter Notebook on a Specific Port

If the default port (8888) is in use, you can specify a different port using:

jupyter notebook --port=8889

This is useful when running multiple Jupyter Notebook instances simultaneously.

Method 4: Open Jupyter Notebook Without Browser Auto-Launch

If you don’t want Jupyter Notebook to open a browser automatically, use:

jupyter notebook --no-browser

Then, copy and paste the displayed URL manually into a browser.

Method 5: Open Jupyter Notebook with a Token or Password

Jupyter Notebook requires authentication via a token. If you need to access it remotely, retrieve the token by running:

jupyter notebook list

The output will display a URL like this:

http://localhost:8888/?token=abcd1234efgh5678

Use this URL to access Jupyter Notebook.

Method 6: Open Jupyter Notebook in a Specific Browser

If you want to open Jupyter Notebook in a browser other than the system default, specify it using:

jupyter notebook --browser=chrome

Replace chrome with firefox, edge, or another installed browser.


3. Troubleshooting Common Issues When Opening Jupyter Notebook

1. ‘Jupyter’ is Not Recognized as an Internal or External Command

If you get the following error:

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

Try these solutions:

  • Ensure Jupyter is installed: pip install notebook
  • Add Python and Scripts directory to the system PATH (Windows users): setx PATH "%PATH%;C:\Users\YourUsername\AppData\Local\Programs\Python\Python39\Scripts"
  • Activate the virtual environment before running jupyter notebook.

2. Jupyter Notebook Does Not Open in Browser

If Jupyter starts but does not open a browser, try manually opening the URL displayed in the terminal (e.g., http://localhost:8888).

3. Address Already in Use Error

If you see a message like:

OSError: [Errno 98] Address already in use

Try running Jupyter Notebook on a different port:

jupyter notebook --port=8890

4. Kernel Error or Notebook Crashes

If the kernel fails to start, reinstall Jupyter dependencies:

pip install --upgrade jupyter
pip install --upgrade ipykernel

5. Permission Denied Error

If Jupyter fails to start due to permission issues, use:

jupyter notebook --allow-root

or change the working directory:

cd ~/notebooks
jupyter notebook


4. Best Practices for Using Jupyter Notebook from CMD

1. Create Aliases for Faster Access

To avoid typing long commands, create shortcuts:

  • Windows: Add an alias to jupyter notebook in PowerShell: function jn { jupyter notebook }
  • Mac/Linux: Add the alias to ~/.bashrc or ~/.zshrc: alias jn='jupyter notebook'

Now, simply type jn to launch Jupyter Notebook.

2. Enable Auto-Restart of Jupyter Notebook Server

Use the following command to restart the Jupyter server if it stops:

while true; do jupyter notebook; done

3. Secure Jupyter Notebook with a Password

To set a password for Jupyter Notebook:

jupyter notebook --generate-config
jupyter notebook password

This prevents unauthorized access when running Jupyter on remote servers.

4. Use Jupyter Notebook Extensions

Enhance functionality with:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

Enable useful extensions like table of contents, code folding, and execution time tracking.

5. Keep Jupyter Notebook Updated

Regularly update Jupyter to avoid compatibility issues:

pip install --upgrade notebook


Conclusion

Opening Jupyter Notebook from CMD is simple and efficient when properly configured. Whether you use jupyter notebook, specify a directory, or launch it on a different port, mastering these commands can significantly improve your data science and Python workflow.

By following best practices, troubleshooting common issues, and optimizing your environment, you can ensure a smooth and productive experience with Jupyter Notebook.

Leave a Comment