I am trying to import matplotlib into an iPython notebook using Wakari, with the Anaconda environment np18py27-1.9. I am importing using:
%matplotlib inline
import matplotlib.pyplot as plt
This yields the error:
ImportError: libpng15.so.15: cannot open shared object file: No such file or directory
Because it is Wakari, I don't think I can update or reinstall the matplotlib package. Importing pylab throws the same error. Do you have any suggestions? Thanks for your help.
Edit:
I was able to update matplotlib in my Wakari environment. I am now getting the following error:
ImportError: libXext.so.6: cannot open shared object file: No such file or directory
Well .so files are shared libraries and (for what reasons I have no idea) you don't have them.
For your second error regarding libXext.so the answers generally suggested are sudo apt-get update && sudo apt-get install libxtst6
Related
I know that this is quite a common problem but when I installed this package I can't seem to get pyplot to be imported with matplotlib. My computer is currently running Pop os and I am using Pycharm as my IDE. When I run anything involved pyplot I get an the console prints out
Traceback (most recent call last):
File "/home/msm/PycharmProjects/Beginner/testing.py", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I have already tried the following
sudo apt-get install python3-matplotlib in the terminal
Searching for the package within Pycharm
Updating Python
Any help would be greatly appreciated.
try:
pip install matplotlib
if it isn't working try:
pip install --upgrade pip
and try it again
if it isn't working again try start terminal with administrator and add python -m to head of code
I am trying to run some code that has 'import websocket' however I am getting the error: ModuleNotFoundError: No module named 'websocket'
I have Python 3.7.3 and I am running in Spyder (if that makes a difference).
So from other questions/answers I found on here, in my cmd I ran pip install websocket and then also pip install websocket-client when the first one didn't run.
I am still getting the ModuleNotFoundError. Does it matter the location/folder of the code or where I install the pip command in cmd?
My python code starts with these import statements:
import json
import websocket
import traceback
import helper
import ssl
import time as time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
from mpl_toolkits.mplot3d import Axes3D
In cmd I ran:
C:\Users\myname>pip install websocket
and also:
C:\Users\myname>pip install websocket-client
The error I am getting is:
File "C:/Users/micki/Downloads/Derbit-Volatility-Visulization-master/Derbit-Volatility-Visulization-master/Volatility Surface Class.py", line 2, in <module>
import websocket
ModuleNotFoundError: No module named 'websocket'
Not sure, as you did not cover how you installed and are using Spyder, though I think it is probably an issue with your environment. You might also find that you are missing the module "helper" as well. There's two easy options as follows:
If you installed and are using Spyder via conda or anaconda, follow their documentation on installing websocket-client to the correct environment found here.
The second option (the preferred option IMHO, as you can use any IDE or text editor going forward), regardless of how you installed Spyder, would be to create a python virtual environment python3 -m venv /path/to/new/virtual/environment, pip install all your dependencies in said environment, then link Spyder's interpreter to the interpereter that was installed when you made the environment. In Spyder, go to Tools -> Preferences -> Python interpreter -> check the "Use the following Python interpreter:" radio button and enter the path to the interpreter from the environment you just created. For reference, see docs on making and using a python venv here.
If the websocket and websocket-client doesn't work, try:
pip install websocket_client
This solved my issue:
sudo pip install websocket-client
I am importing the Basemap package from mpl_toolkits.basemap.
from mpl_toolkits.basemap import Basemap
Tried: Updating the version of matplotlib
But still, it throws an error:
ImportError: cannot import name 'is_scalar'
I found this on GitHub, maybe one of these solutions will work for you.
I had the same problem, it appears to have been fixed in a newer version of basemap. After compiling from source it worked for me
git clone https://github.com/matplotlib/basemap.git
cd basemap
pip install .
After doing this, you can test your basemap installation to verify it works correctly:
cd examples
python simpletest.py
I installed matplotlib using conda:
conda install matplotlib
The following code failed:
#!/usr/bin/env python
import matplotlib
import matplotlib.pyplot as plt
With this error message:
"ImportError: No module named 'matplotlib.pyplot'"
I tried installing matplotlib with apt-get:
sudo apt-get install python3-matplotlib
I got the same error.
I tried loading matplotlib with ubuntu application load and got the same error.
I tried cloning from GitHub with:
git clone git://github.com/matplotlib/matplotlib.git
I got the same error.
I looked at the matplotlib directory and did not see a pyplot.py entry. I did find pyplot.py in matplotlib/lib/matplotlib. I copied it to matplotlib. The error went away, but I got another module that pyplot was trying to include. I found it in matplotlib/lib/matplotlib. I copied it to matplotlib. Got another error for another module. Copied it. Eventually I got an error for a module I could not find.
I do not know what to try next.
Normally conda isn't added to your path (it asks you during the installation if it should do that but the default is "no"), so the default python will be the systems Python 2 (you start Python 3 with python3).
You could verify this by using:
$ which python
That will return the path associated with the python command. Likely this will return the path to the systems Python 2 "installation".
For example on my Ubuntu machine the commands which python and which python3 return:
usr/bin/python (starts Python 2.7.12)
usr/bin/python3 (starts Python 3.5.2)
While my conda installation is somewhere in the /home/michael/miniconda directory.
There are several options how you could use the conda Python:
Temporarily add the conda directory it to the PATH. (See for example How to add [...] to path)
Permanently add the conda directory to the PATH. (see for example How to add a directory to the path)
Use the anaconda promt which gives you a terminal with the conda directory prepended to the PATH.
I am starting to get some insight into interactive plotting with python and matplotlib using pyGTK+. Therefore I took a look at the example given at the matplotlib website.
This is a short exerpt of the Code:
#!/usr/bin/env python
"""
Example of embedding matplotlib in an application and interacting with
a treeview to store data. Double click on an entry to update plot
data
"""
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
import matplotlib
matplotlib.use('GTKAgg') # or 'GTK'
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from numpy.random import random
from matplotlib.figure import Figure
Ones I try to run this Script in the Terminal I get the following error:
Traceback (most recent call last):
File "gtk_spreadsheet.py", line 15, in <module>
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 33, in <module>
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_gdk.py", line 29, in <module>
from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk
I have python 2.7 and pygtk 2.24 installed.
Can anyone figure out where the error is located? I think it might be connected to some linking issues?
Note that the Debian/Ubuntu package you need is not 'pygtk2-devel' but 'python-gtk2-dev':
sudo apt-get install python-gtk2-dev
should fix this error on these platforms.
This was a symptom of using a pip-installed matplotlib instead of an apt-installed matplotlib on my system, just now. If on Ubuntu/Debian, try:
pip uninstall matplotlib
apt install python-matplotlib
I believe what was happening is that the pip-install didn't build the C extension required for GTK output, but the apt package has the extension prebuilt. I don't have logs from the initial pip install of matplotlib, so I can't confirm that that's what happened.
In addition to Haldean Brown's answer, note that if you really need to use pip you can force it to recompile matplotlib locally and get "the deep magic that setup.py does" with the --no-binary option:
pip uninstall matplotlib
pip install matplotlib --no-binary=matplotlib
This will solve your problem, provided that you already installed gtk2 with sudo apt-get install python-gtk2-dev
As you want to use the GTKAgg backend, Using pip may prove useful in the future to freeze matplotlib at a version where it is supported (the deprecation warning states it will be dropped in 3.0):
pip install matplotlib==2.2.2 --no-binary=matplotlib
Ubuntu 18.04 has a broken matplotlib package. See this bug: https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/1785458
You can either compile matplotlib yourself (e.g. with pip) or use the PPA linked from the bug report.
if you are running py2.7 applications, try:
pip2 install matplotlib --no-binary=matplotlib