Jupyter Notebook 500 : Internal Server Error

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:

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/", line 1443, in _execute result = method(*self.path_args, **self.path_kwargs) File "/opt/local/Library/Frameworks/", line 2800, in wrapper return method(self, *args, **kwargs) File "/opt/local/Library/Frameworks/", line 50, in get terminals_available=self.settings['terminals_available'], File "/opt/local/Library/Frameworks/", line 302, in render_template template = self.get_template(name) File "/opt/local/Library/Frameworks/", line 298, in get_template return self.settings['jinja2_env'].get_template(name) File "/opt/local/Library/Frameworks/", line 719, in get_template return self._load_template(name, self.make_globals(globals)) File "/opt/local/Library/Frameworks/", line 693, in _load_template template = self.loader.load(self, name, globals) File "/opt/local/Library/Frameworks/", line 127, in load code = environment.compile(source, name, filename) File "/opt/local/Library/Frameworks/", line 493, in compile self.handle_exception(exc_info, source_hint=source) File "/opt/local/Library/Frameworks/", line 8, in template 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/", line 209, in main status = self.run(options, args) File "/opt/local/Library/Frameworks/", line 317, in run prefix=options.prefix_path, File "/opt/local/Library/Frameworks/", line 732, in install **kwargs File "/opt/local/Library/Frameworks/", line 835, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/opt/local/Library/Frameworks/", line 1030, in move_wheel_files isolated=self.isolated, File "/opt/local/Library/Frameworks/", line 247, in move_wheel_files prefix=prefix, File "/opt/local/Library/Frameworks/", line 142, in distutils_scheme i = d.get_command_obj('install', create=True) File "/opt/local/Library/Frameworks/", line 845, in get_command_obj klass = self.get_command_class(command) File "/opt/local/Library/Frameworks/", line 430, in get_command_class self.cmdclass[command] = cmdclass = ep.load() File "/opt/local/Library/Frameworks/", line 2229, in load return self.resolve() File "/opt/local/Library/Frameworks/", line 2235, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named command.install
3

34 Answers

12

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

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

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

I solved this by upgrading the nbconvert package

pip install --upgrade --user nbconvert
0

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

Solved error on Linux(CentOS 7) using

pip3 install --user --upgrade nbconvert

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

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

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.

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

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

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

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

The same problem here. Using Pop!_OS as VM

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

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.

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

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.

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.

Use this ::

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

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.

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.

You can use

python3 pip install nbconvert==5.4.1 

(for python 3.6; Linux Mint)

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>

Reading jupyter lab error code at terminal was helpful.

Try:conda install nodejs

Additional instructions to follow:

Environment: macOS Big Sur, conda 4.11.0

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

conda install -c conda-forge pandoc

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

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.

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

pip install -U jupyter

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

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.

12

You Might Also Like