Ubuntu: Kernel dead in jupyter notebook, matplotlib seems not to work



Question:

I recently updated my anaconda package with $conda update conda and then $conda update anaconda After that update my matplotlib is not working anymore and every time I try to run Jupyter notebook and import matplotlib, it says 'The kernel appears to have died. It will restart automatically.'

And it leaves with a ton of message starting like this:

Bad key "patch.force_edgecolor" on line 33 in  /home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle.  You probably need to get an updated matplotlibrc file from  http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template  or from the matplotlib source distribution  

I am using Ubuntu 16.04 LTS and python 2.7 . Any suggestion on how to fix this issue?


Solution:1

If you don't want to mess up the matplotlib that you already have installed in Anaconda, you can install second instance of matplotlib inside a Python virtual environment (virtualenv) alongside the matplotlib that is installed in Anaconda. Installing Jupyter, matplotlib and whatever else you need with pip is easy and straightforward in virtualenv.

virtualenv allows you to create a sandboxed and isolated environment where Python packages can be installed without interfering with other packages on the same machine.

  1. Install Python virtual environment creator (virtualenv):

    sudo apt install python-virtualenv virtualenv    
  2. Make a new directory (I'll call it PythonVirtualEnv in this example) for the Python virtual environment and setup the Python virtual environment with Python and pip in it.

    cd ~    mkdir PythonVirtualEnv  virtualenv PythonVirtualEnv   
  3. Install some packages.

    cd ~/PythonVirtualEnv    source bin/activate  pip install jupyter matplotlib   
  4. Deactivate the Python virtual environment before leaving it.

    deactivate    

Creating an environment with a custom Python interpreter

sudo apt install python3-virtualenv   cd ~    mkdir Python3VirtualEnv  virtualenv --python=/usr/bin/python3 Python3VirtualEnv # /usr/bin/python3 is the default location of the python3 executable  cd ~/Python3VirtualEnv    source bin/activate  pip3 install jupyter matplotlib    


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »