Error when import matplotlib.pyplot as plt

2024/10/18 12:59:52

I did not have any problem to use "plt", but it suddenly shows an error message and does not work, when I import it. Please see the below.

>>> import matplotlib
>>> import matplotlib.pyplot as plt

Output:

Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 6, in <module>from matplotlib.figure import Figure, figaspectFile "/usr/lib64/python2.6/site-packages/matplotlib/figure.py", line 18, in <module>from axes import Axes, SubplotBase, subplot_class_factoryFile "/usr/lib64/python2.6/site-packages/matplotlib/axes.py", line 2, in <module>import math, sys, warnings, datetime, newFile "new.py", line 12, in <module>import matplotlib.pyplot as pltAttributeError: 'module' object has no attribute 'pyplot'

This package is suddenly corrupted. So, I tried to install as below. I use Ubuntu.

In [1]: sudo apt-get install python-matplotlibFile "<ipython-input-1-2400ac877ebd>", line 1sudo apt-get install python-matplotlib^
SyntaxError: invalid syntax

If I need to reinstall, what are the detailed instructions on how to do it?

I am very new to Python. So, my problem might be too simple to be solved. But I cannot.

Answer

Try to type sudo apt-get install python-matplotlib in a terminal. In your message you typed it in the IPython console. This is a Bash command, not a Python one.

You need to quit IPython before. For that use Ctrl + D.

https://en.xdnf.cn/q/72713.html

Related Q&A

Python NtQueryDirectoryFile (File information structure)

Ive written a simple (test) script to list files in a selected directory. Not using FindFirstFile; only native API. When I execute the script and watch, Win32API monitor tells me STATUS_SUCCESS. My Fil…

returning A DNS record in dnspython

I am using dnspython to get the A record and return the result (IP address for a given domain).I have this simple testing python script:import dns.resolverdef resolveDNS():domain = "google.com&quo…

IO completion port key confusion

Im writing an IO completion port based server (source code here) using the Windows DLL API in Python using the ctypes module. But this is a pretty direct usage of the API and this question is directed…

PySpark reversing StringIndexer in nested array

Im using PySpark to do collaborative filtering using ALS. My original user and item ids are strings, so I used StringIndexer to convert them to numeric indices (PySparks ALS model obliges us to do so).…

Numba np.convolve really slow

Im trying to speed up a piece of code convolving a 1D array (filter) over each column of a 2D array. Somehow, when I run it with numbas njit, I get a 7x slow down. My thoughts:Maybe column indexing is …

Python: Retrieving only POP3 message text, no headers

Im trying to make a Python program that retrieves only the body text of an email without passing headers or any other parameters. Im not sure how to go about this.The goal is to be able to send basic c…

Getting text between xml tags with minidom [duplicate]

This question already has answers here:Getting text values from XML in Python(2 answers)Closed 9 years ago.I have this sample xml document snippet<root><foo>bar</foo><foo>baz<…

OpenCV Error: Unknown error code -49 in Python

I am trying to learn face detection in python-3.6 using cv2.I follow the src given in a book.I have already installed opencv-python(3.2.0) by pip.xml and .jpg files are all in the same path with python…

Python Exchange ActiveSync Library

Is anyone familiar with an Exchange ActiveSync library or open source client for python? Ive done preliminary searching with little to no success. Ive seen some examples for C#, but I figured Id ask a…

Tastypie: How can I fill the resource without database?

I want to grab some information from Foursquare , add some fields and return it via django-tastypie. UPDATE:def obj_get_list(self, request=None, **kwargs):near = if near in request.GET and request.GET…