error while importing matplotlib

So, here I was trying my hands on ipython notebook, when the following commands generated an error.

import matplotlib.pyplot as plt
import numpy as np

At first I thought it was due to some configuration issues with my notebook but when I tried the above commands on python via terminal, the same error surfaced.

ImportError: cannot open shared object file: No such file or directory

It looked like either some files were missing or the interpreter was looking for them somewhere else.

Following the solutions on Stackoverflow-

Check the value of LD_LIBRARAY_PATH, do:
As expected, it returned an empty string, which meant I had to change its value.
Change the value of LD_LIBRARAY_PATH,do:
In my case it was /home/sarah/anaconda/lib, you can check for yours using

The solution did not work for me, in fact it is a temporary one, once the system is switched off, the exported path would be lost. You can make it permanent by adding the above line at the end of your .bashrc file and then running:

source .bashrc

Caution! appending the above lines to my .bashrc, rendered useless running my text editors from the terminal,

So I had to redo the changes. Looked like things were real bad.

I had two more option before me, to either install/reinstall the libpng from package manager or do it manually.
Shortcuts first,

sudo apt-get install zlib1g-dev
sudo apt-get install libpng-dev
sudo apt-get update

With hopes that my system will resolve the missing links, now that it had been updated. But, it did not, because the package manager still used the libping12 while I needed  libpng15.

Left will no other option,here is what finally worked:

D/w the latest tar of libpng
Un-tar it and move inside the folder
sudo make install
sudo ln -s /usr/local/lib/ /usr/lib
sudo ln -s /usr/local/lib/ /usr/ib

Testing time:

$ subl (opened without error)
Fingers crossed
$ python
>>import matplotlib.pyplot as plt

No errors.

Credits:Shivam 😉


2 thoughts on “ error while importing matplotlib

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s