Jupyter Notebook 500 : Internal Server Error

PythonPipJupyter Notebook

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

Solution 3 - Python

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]

Solution 4 - Python

I solved this by upgrading the nbconvert package

pip install --upgrade --user nbconvert

Solution 5 - Python

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 

Solution 6 - Python

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.

Solution 7 - Python

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

Solution 8 - Python

Solved error on Linux(CentOS 7) using

pip3 install --user --upgrade nbconvert

Solution 9 - Python

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.

Solution 10 - Python

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

Solution 11 - Python

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

Solution 12 - Python

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.

Solution 13 - Python

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

Solution 14 - Python

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.

Solution 15 - Python

Use this ::

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

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

Solution 16 - Python

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.

Solution 17 - Python

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.

Solution 18 - Python

I was able to fix this issue by eliminating any spaces between my LaTeX code and the $.

For example:

$\frac        

instead of

$ \frac 

Solution 19 - Python

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

Solution 20 - Python

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.

Solution 21 - Python

You can use

python3 pip install nbconvert==5.4.1 

(for python 3.6; Linux Mint)

Solution 22 - Python

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>

Solution 23 - Python

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

Solution 24 - Python

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

conda install -c conda-forge pandoc

Solution 25 - Python

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

Solution 26 - Python

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.

Solution 27 - Python

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

pip install -U jupyter

Solution 28 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1551817View Question on Stackoverflow
Solution 1 - PythonkrugerView Answer on Stackoverflow
Solution 2 - PythonIsopycnal OscillationView Answer on Stackoverflow
Solution 3 - PythonEhab AlBadawyView Answer on Stackoverflow
Solution 4 - Pythonf.cView Answer on Stackoverflow
Solution 5 - PythonHadis BagherpourView Answer on Stackoverflow
Solution 6 - PythonscannyView Answer on Stackoverflow
Solution 7 - PythonGihan SamarasingheView Answer on Stackoverflow
Solution 8 - PythonYashraj NigamView Answer on Stackoverflow
Solution 9 - PythonSolomon VimalView Answer on Stackoverflow
Solution 10 - PythonVidush5View Answer on Stackoverflow
Solution 11 - PythonMadhuparna BhowmikView Answer on Stackoverflow
Solution 12 - Pythonsanjeet palView Answer on Stackoverflow
Solution 13 - PythonjadkiView Answer on Stackoverflow
Solution 14 - PythonmaikeloView Answer on Stackoverflow
Solution 15 - PythonAkash KandpalView Answer on Stackoverflow
Solution 16 - PythonArnab SinhaView Answer on Stackoverflow
Solution 17 - PythonAhmet BirimView Answer on Stackoverflow
Solution 18 - PythonEnrique PerezView Answer on Stackoverflow
Solution 19 - Pythonshyam_guptaView Answer on Stackoverflow
Solution 20 - PythonWong Tat YauView Answer on Stackoverflow
Solution 21 - PythonВиталийView Answer on Stackoverflow
Solution 22 - Pythonkushagra deepView Answer on Stackoverflow
Solution 23 - PythonStuberView Answer on Stackoverflow
Solution 24 - Pythonruddy simonpourView Answer on Stackoverflow
Solution 25 - PythonSrikrishna Krishnarao SrinivasView Answer on Stackoverflow
Solution 26 - PythonSachin MotwaniView Answer on Stackoverflow
Solution 27 - PythonAdityaView Answer on Stackoverflow
Solution 28 - PythonUjwala ShindeView Answer on Stackoverflow