Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Kernel dead in jupyter notebook, matplotlib seems not to work

Writer Matthew Barrera

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
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?

0

1 Answer

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 # still works in 22.04 
  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
    python -m 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
python3 -m pip install jupyter matplotlib 
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy