123

I want to learn how to use Jupyter Notebook. So far, I have managed to download and install it (using pip), but I'm having trouble opening it.

I am opening it by typing:

jupyter notebook

in my terminal. It opens in my browser, with the URL:

http://localhost:8888/tree

and I just get a big:

500 : Internal Server Error

message. Could someone point me in the right direction of what's going wrong please?

The full error message in my terminal:

[E 17:53:52.034 NotebookApp] Uncaught exception GET /tree (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/tree', version='HTTP/1.1', remote_ip='::1', headers={'Accept-Language': 'en-US,en;q=0.8,es;q=0.6', 'Accept-Encoding': 'gzip, deflate, sdch', 'Host': 'localhost:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1'})
    Traceback (most recent call last):
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/web.py", line 1443, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/web.py", line 2800, in wrapper
        return method(self, *args, **kwargs)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/tree/handlers.py", line 50, in get
        terminals_available=self.settings['terminals_available'],
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/base/handlers.py", line 302, in render_template
        template = self.get_template(name)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/base/handlers.py", line 298, in get_template
        return self.settings['jinja2_env'].get_template(name)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 719, in get_template
        return self._load_template(name, self.make_globals(globals))
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 693, in _load_template
        template = self.loader.load(self, name, globals)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/loaders.py", line 127, in load
        code = environment.compile(source, name, filename)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py", line 493, in compile
        self.handle_exception(exc_info, source_hint=source)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/notebook/templates/tree.html", line 8, in template
        data-base-url="{{base_url | urlencode}}"
    TemplateAssertionError: no filter named 'urlencode'
[E 17:53:52.819 NotebookApp] {
      "Accept-Language": "en-US,en;q=0.8,es;q=0.6",
      "Accept-Encoding": "gzip, deflate, sdch",
      "Host": "localhost:8888",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36",
      "Connection": "keep-alive",
      "Upgrade-Insecure-Requests": "1"
    }
[E 17:53:52.819 NotebookApp] 500 GET /tree (::1) 874.29ms referer=None

EDIT

When attempting to update ipython as advised, the following error message was produced:

Exception:
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 835, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 1030, in move_wheel_files
    isolated=self.isolated,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/wheel.py", line 247, in move_wheel_files
    prefix=prefix,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/locations.py", line 142, in distutils_scheme
    i = d.get_command_obj('install', create=True)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 845, in get_command_obj
    klass = self.get_command_class(command)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/dist.py", line 430, in get_command_class
    self.cmdclass[command] = cmdclass = ep.load()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named command.install
3
  • The second error suggests there's something quite wrong with your Python installation.
    – Thomas K
    Commented Apr 26, 2016 at 11:35
  • 1
    Consider always using Python virtual environments, it will save you a lot of time in the future. ;-) Have a look at virtualenvwrapper or miniconda.
    – Peque
    Commented Apr 26, 2016 at 11:45
  • consider using python 3.7 version Commented Mar 22, 2020 at 5:20

37 Answers 37

158

Try upgrading jupyter hub first:

pip install --upgrade jupyterhub
pip install --upgrade --user nbconvert

If you are inside a conda environment, run the following command instead.

conda install nbconvert==5.4.1
0
92

After trying all the solutions on this page without success, a variation of @kruger answer is what worked for me, simply this:

pip install --upgrade nbconvert

2
  • 3
    The command works for me as well: pip install --upgrade --user nbconvert
    – ah bon
    Commented Apr 25, 2021 at 14:15
  • upgrading nbconvert worked Commented Apr 21, 2023 at 22:16
30

Was having a similar problem. Fixed it after upgrading ipython with this command

sudo pip install --upgrade "ipython[all]"

Note: make sure to type ipython with double quotes and [all]

5
  • Thank you. I tried to do this. It started to update, but I got an error message, which I will add as an edit to my main post. Commented Apr 26, 2016 at 0:16
  • 1
    try to uninstall and re-install ipytohn again, it mat has some conflicts with other packages. If you could have a cleaner version of the error message that would be much better (maybe a screenshot) Commented Apr 26, 2016 at 10:54
  • 8
    Maybe pip install --upgrade jupyter is better. :-)
    – Peque
    Commented Apr 26, 2016 at 11:45
  • Didn't do it for me, but stackoverflow.com/questions/55013206/… did. Commented Dec 17, 2020 at 13:09
  • This sudo pip install --upgrade "ipython[all]" worked for me
    – Loui
    Commented Sep 10, 2023 at 10:35
20

I solved this by upgrading the nbconvert package

pip install --upgrade --user nbconvert
0
18

I had the same problem and was a bit painful until I managed to fix it. The magic line the worked for me was

conda install -c conda-forge jupyter_contrib_nbextensions 
2
  • Same for me, error about "wrong color format %r" % text Commented Oct 23, 2020 at 19:34
  • 1
    Helped me with 500 error and ModuleNotFoundError: No module named 'yaml'
    – marizombie
    Commented Jun 29, 2021 at 10:23
8

Solved error on Linux(CentOS 7) using

pip3 install --user --upgrade nbconvert
7

I also encountered this problem. The root cause in my case was that I already had Jinja2 installed with root permissions (having used sudo pip install before I knew better).

My solution was to uninstall Jinja2 with sudo pip uninstall (which was required because it was installed with root permissions), and re-run pip install jupyter to reinstall it with regular user permissions.

$ sudo pip uninstall Jinja2
$ pip install jupyter

While using sudo to install works here, it makes the problem worse in the longer term because all its packages are installed with root permissions, leading to further problems like this in future with other packages. It's kind of like kicking that can down the road.

Many won't care of course, as long as it works. But for those that do I thought I'd mention.

There's no way to know for sure what the offending package is, but it's likely to be one of those in the stack trace. I noticed Jinja2 as one I vaguely remembered from my early days in Python so I started there and it worked.

1
  • pip install --user may be the command you would prefer. That way, pip installs local to the user and does not require admin privileges. Commented Nov 29, 2016 at 23:01
6

I had this issue as of 22/03/2019, and what worked for me was updating conda and then upgrading jupyter using pip:

conda update --all
pip install jupyter --upgrade
5

A simple solution that worked for me: on the terminal, run the following command -

jupyter troubleshoot | grep jupyter | grep /

This will list the path to the different versions of jupyter that are installed in your computer. Try all the versions one by one and delete the binaries of the ones that give you the 500 error. Then you might want to change the link to jupyter by adding a line (alias jupyter="/usr/local/bin/jupyter") to your ~/.bashrc file or call jupyter with the absolute path.

Note: this is not the cleanest solution, but one that works.

5

I was running into a similar issue with the error cause being

 ImportError: cannot import name 'contextfilter' from 'jinja2'

I tried removing Jinja2 which caused Jupyter to stop working and after this i tried upgrading my nbcovert which was the real reason for the error and the issue was resolved.

pip install --upgrade nbconvert
5

I simply drop my answer here, I face the same issue and none of the above answer work for me then i see Jupyter terminal it shows an error. ERROR

enter image description here

then i can simply install the missing package using command pip install appdirs. My point is that if you are unable to solve this error then check the terminal which package is missing then install it seperatly.

0
4

This error is due to inconsistencies. Updating jupyter solves the issue. Use the following command if you are using Anaconda- conda update jupyter

3

I faced this issue and solved by reinstalling it.

To uninstall:

pip uninstall -y jupyter jupyter_core jupyter-client jupyter-console jupyterlab_pygments notebook qtconsole nbconvert nbformat

To reinstall:

pip install jupyter
3

The same problem here. Using Pop!_OS as VM

pip install --upgrade nbconvert
pip install --upgrade nbclient
pip install --upgrade prompt-toolkit
2

I am having the same problem but solve it by using python 3.7 with four simple steps:

step 1:Installing python 3.7 in linux

sudo apt-get install python3.7

step 2: Installing python3-pip

sudo apt install python3-pip

step 3: installing jupyter

pip3 install jupyter

step 4:Strting jupyter notebook server

jupyter notebook

after starting server and going to localhost:888/tree it show option to create python 3 file after clicking on new button.

2

I experienced this issue on my Windows machine while running an outdated version of Python. Specifically, I solved this issue for myself from upgrading from Python 3.6.0 to Python 3.6.8

2

This Permission error is caused due to the version of nbconvert. I have downgraded the nbconvert to 5.6.1 and it fixed the issue for me. I no longer face the Permission error any more while trying to open .ipynb files.

1

I had the same problem and my solution was update the Jinja2 package to version Jinja2-2.8.

To update it I used the easy_install command as follow:

sudo easy_install -U python-jinja2[all]

After that the 500 : Internal Server Error was fixed.

1

Use this ::

python2 -m pip install ipykernel
python2 -m ipykernel install --user

python3 -m pip install ipykernel
python3 -m ipykernel install --user
1

I just had to shut down jupyter kernel and restart it again. It is probably because I uninstalled and installed a few of jupyter dependencies whilst the current kernel was still active.

1

My problem fixed after changing the kernel in the notebook. Old one seemed broken.

From notebook menu select:

Kernel > change kernel > "select whatever kernel from the list".

Consider creating one if you don't have any before.

1

You can use

python3 pip install nbconvert==5.4.1 

(for python 3.6; Linux Mint)

1

This error generally happens when your jupyter notebook is not linked to any conda environment. This linking can be automatically done by installing nb_conda and nb_convert.

conda install nb_conda
conda install nb_convert==5.4.1

Also if this doesnt fix the problem, then the environment can be manually linked. For manual linking you have to first activate your conda environment and then launch jupyter notebook. PS : Dont launch your jupyter notebook from the (base) conda environment

conda activate <env-name>
jupyter notebook --allow-root --port=<port-number>
1

Reading jupyter lab error code at terminal was helpful.

Try: conda install nodejs

Additional instructions to follow: https://anaconda.org/conda-forge/nodejs

Environment: macOS Big Sur, conda 4.11.0

1

I had the same issue, and this command helped me eventually.

conda install -c conda-forge pandoc
1

I had the same issue. First I tried the following steps:

  1. Open Anaconda
  2. Open Powershell Prompt from Anaconda
  3. Run the command below. But I got the error 'PackageNotInstalledError'
conda update jupyter
  1. Go back to Anaconda navigator and click on Environments
  2. Some packages are displayed with a suggestion to upgrade
  3. Click on each one and accept to upgrade. If there are multiple repeat for each of them
  4. Now launch Jupyter notebook from Anaconda. It opened for me without the error 'internal server error 500'

enter image description here

1

Almost all the answers tell you the same thing. Here is what worked for me.

Foremost, try to ping your internal server, if it is working well. If the request times out, possibly there is no problem with your jupyter notebook. Rather, try changing the port number in the URL - there is a strong possibility that it is landing you at the wrong port. In my case, I was landing at 8890 while my lost host port was 8888 (general case). So just correct your URL and things should work just fine for you.

1

I also faced this issue so used this command and later restarted by AWS VM and started working.

pip install -U jupyter
0

In my case it was different

I was running my jupyter notebook from a different environment

so as I activated the environment

The error was solved...

thankyou

0

You likely screwed up somewhere during the jupyter notebook installation.

In your environment, uninstall your jupyter completely. Then, use conda to install jupyter notebook, let conda to resolve the dependency for you.

Step 1 : Uninstall jupyter completely.

python3 -m pip uninstall -y jupyter jupyter_core jupyter-client jupyter-console jupyterlab_pygments notebook qtconsole nbconvert nbformat

Step 2: Install jupyter notebook using conda.

conda install -c conda-forge notebook 
conda install -c conda-forge nb_conda_kernels

Relaunch your notebook.

Not the answer you're looking for? Browse other questions tagged or ask your own question.