cannot import matplotlib.pyplot - python

I have installed the matplotlib in python,and when I import matplotlib,it works well.But when I import matplotlib.pyplot as plt,the command line prompt me that an importerror occurred.
ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/nju/anaconda2/envs/tensorflow/lib/python2.7/site-packages/matplotlib/_path.so)
How can I solve the problem?
Thanks very much

sudo apt install libgl1-mesa-glx
Above command is from the link below.
https://github.com/ContinuumIO/docker-images/issues/49

Related

WinError 193 %1 is not a valid Win32 application

I'm trying to import these libraries in python using this code:
import matplotlib as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
I get this error when I start debugging
Message=[WinError 193] %1 is not a valid Win32 application
Source=C:\Users\basse\source\repos\PythonApplication1\PythonApplication1\PythonApplication1.py
StackTrace:
File "C:\Users\basse\source\repos\PythonApplication1\PythonApplication1\PythonApplication1.py", line 2, in <module> (Current frame)
import matplotlib as plt
These are the commands that I used in Visual Studio's terminal to install the libaries:
pip install matplotlib
pip install pandas
pip install numpy
pip install sklearn
pip install pandas-datareader
pip install beautifulsoup4
What should I do to solve this problem? Please consider that I'm kind of a beginner so make your answer detailed. Thanks!
Edit: I always get the same error with the 4 lines of code. For example, if the first line is import pandas as pd, I'll also get the same error.

Python: Imported matplotlib but cannot use imshow

I'm working in Ubuntu as Virtual-Box guest on top of Windows machine (as host), and I am attempting to run my python script from the terminal. I had difficulty installing matplotlib using pip install. I managed to install it using
sudo apt-get install python-matplotlib
However, I am unable to bring up an image I have created in my code:
import numpy as np
import matplotlib.pyplot as plt
import random as random
from random import randrange
image = plt.imshow(mymatrix)
plt.show()
If I import matplotlib as:
import matplotlib as plt
I am recieving the following error on attempting to run the script:
AttributeError: 'module' object has no attribute 'imshow'
If I import matplotlib as:
import matplotlib.pyplot as plt
I recieve the following error:
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk
package
On attempting to install python-tk using 'pip install python-tk' this is what I'm getting:
~/ising $ pip install python-tk Collecting python-tk Could not find
a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
I'm unsure if I have in fact incorrectly installed matplotlib from the beginning. I am aware pyplot is not automatically imported with matplotlib, could the same be true for installing it from the console? Seems like I have tried everything at this stage.
The problem appears to be that you do not have a graphical backend installed. The error you are getting about Python Tk is happening because normally Tk comes with any Python distribution, so you should have at least that. You can install any Python bindings for Tk, Pyqt4, Pyqt5, Wx, GTK, (possibly others) to get a working interactive graphical backend. Check the package repository for the actual package names to install.
Keep in mind that functions like imshow are part of the (sub)package matplotlib.pyplot, not matplotlib itself. import matplotlib as plt is simply wrong if you intend to do plt.imshow(...). The correct import is either from matplotlib import pyplot as plt or import matplotlib.pyplot as plt.
According to the documentation here try this
python -mpip install -U pip
python -mpip install -U matplotlib

ImportError: No module named filters

I installed skimage in ubuntu terminal using command:
sudo apt-get install python-skimage
it installed succesfully but when using it in my code (from skimage.filters import threshold_local). i get an error:
Traceback (most recent call last):
File "scan.py", line 4, in <module>
from skimage.filters import threshold_local
ImportError: No module named filters
kindly someone help me to correct this!
The problem is resolved now :D. What I found is that there is no module named 'filters' in skimage '0.10.1' as it has 'filter'. So, when I upgraded it using the command
sudo pip install --upgrade scikit-image
to version '0.13.1', it comes with the 'filters' module instead of 'filter'. The 'filters' module has all attributes of thresholding including 'local' and others as well.
So I got same problem in Spyder, Python 3.6.6.
this code (with img being a np array):
import skimage
val = skimage.filters.threshold_otsu(img)
gives: module 'skimage' has no attribute 'filters'
I tried pip install --upgrade scikit-image with no change. Skimage is indeed in my system path:
*'C:\WPy-3661\python-3.6.6.amd64\lib\site-packages', and the filters folder is in there with the init file.
but if i do:
from skimage import filters as anything
val = skimage.filters.threshold_otsu(img)
then it works. This is not normal, right ?
Note that in my sys.path paths there is only one skimage folder. So I don't think it's a duplicate issue.
I had also same problem but below code helped me:
!sudo apt-get install python-skimage
from skimage.filters import roberts, prewitt, sobel, scharr, laplace

How can I import odeint and arange in Python?

I am trying to import odeint in python by doing:
from scipy.integrate import odeint
but there is an error note:
ImportError: No module named scipy.integrate
I have looked through some websites and there is a module called scipy.integrate, I am not sure what is going wrong with my code?
I also tried
from scipy import arange
which also shows similar error message:
ImportError: No module named scipy
I am using Python 2.7.8. Is it due to the version of Python? How can I fix it then?
If I could not even import them, I won't be able to continue writing my code.
Could somebody please give some advice?
Thanks.
This happens when scipy is not installed.
Download & Install SciPy from : Scientific Python
Ubuntu & Debian : sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Fedora: sudo yum install numpy scipy python-matplotlib ipython python-pandas sympy python-nose
Windows : Unofficial Windows Binaries for Python Extension Packages
SciPy source

numpy.core.multiarray failed to import

I used the following command to know the numpy version I am using
pip show numpy
output shown below
---
Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages
Requires:
However when I am running matplotlib, I got a error as
RuntimeError: module compiled against API version a but this version of numpy is 9
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/usr/local/lib/python2.7/dist-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
I tried to upgrade numpy,
pip install numpy --upgrade
it shows to be installed successfully, but numpy still shows to be 1.8.2 and error continues to exist when running matplotlib.
I thought to uninstall numpy and reinstall it, the system gives the message saying
Not uninstalling numpy at /usr/lib/python2.7/dist-packages, owned by OS
how to solve it ?
any idea about
RuntimeError: module compiled against API version a but this version
of numpy is 9
How can I upgrade numpy? might be working for you. IN that case it was a path problem:
RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
Solution:
Check the path
import numpy
print numpy.__path__
and manually delete it using rm
I also had the same problem until I came across this Issue on Pytorch github repository. This command worked perfectly for me:
pip install numpy -I
It is also mentioned there that pip install numpy --upgrade is not working(don't know why). You can check the above mentioned link.
I had a similar problem with numpy when running torch. I tried uninstalling numpy and installing it using -U but it didn't work. After some search, I found this link and it solved my problem. It says you should change your numpy version.
pip uninstall numpy
pip install numpy==1.19.3
The answer is probably simple.
Just add
import numpy.core.multiarray
before the
import cv2
statement.
It worked fine for me.
My problem is solved using the old version of numpy. The solution is to use numpy 1.19.3.
pip install numpy==1.19.3
Credit: https://stackoverflow.com/a/64730012
Installing the previous version of NumPy, 1.19.3 should fix this.
python -m pip install numpy==1.19.3

Categories

Resources