I'm trying to import and use matplotlib.pyplot in a script and I'm getting the following error:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
from matplotlib import pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/figure.py", line 40, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/__init__.py", line 4, in <module>
from ._subplots import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/_axes.py", line 22, in <module>
import matplotlib.dates as _ # <-registers a date unit converter
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/dates.py", line 126, in <module>
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/dateutil/rrule.py", line 13, in <module>
from fractions import gcd
ImportError: cannot import name 'gcd'
The weird part is that I can import it just fine if I restart the Python shell and import it directly, but as soon as I try to run my script, even if I run the script and then import it after running the script to generate data, I get the error. The import line, if it matters, is always the same:
import matplotlib
from matplotlib import pyplot
My script is being run from a folder on my desktop, and I installed matplotlib in terminal with pip3.
Your file called fractions.py is shadowing the builtin module of the same name, causing problems when other libraries try to use that library. Name your file something else.
Related
Everytime I import matplotlib into my python programs I get this error (here the program is just one line "import matplotlib.pyplot as plt"):
Traceback (most recent call last):
File "string.py", line 1, in \<module>
import matplotlib.pyplot as plt
File "D:\Other programs\Python38\lib\site-packages\matplotlib\__init__.py", line 94,
in \<module>
import logging
File "D:\Other programs\Python38\lib\logging\__init__.py", line 28, in \<module>
from string import Template
File "D:\programs\python\string.py", line 1, in \<module>
import matplotlib.pyplot as plt
File "D:\Other programs\Python38\lib\site-packages\matplotlib\pyplot.py", line 36, in \<module>
import matplotlib.colorbar
File "D:\Other programs\Python38\lib\site-packages\matplotlib\colorbar.py", line 40, in \<module>
import matplotlib.artist as martist
File "D:\Other programs\Python38\lib\site-packages\matplotlib\artist.py", line 17, in \<module>
_log = logging.getLogger(__name__)
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely
due to a circular import)
I cannot find any logging.py anywhere. Is this some sort of bug in the lates version of matplotlib?
your script D:\programs\python\string.py, where you try to import matplotlib.pyplot as plt is named string.py and it interferes with string module from standard library. Rename that file.
These are the messages I'm receiving and I have no idea what any of them mean.
I have python 2.7.12 and have imported matplotlib.
In the command prompt window, the last update I installed was conda install matplotlib which seemed to update some stuff (conda-env-2.5.2 and conda-4.1.12), but unfortunately not the stuff I needed.
I have never used any of this before so please speak in layman's terms if possible.
Traceback (most recent call last):
File "C:\Users\user\Desktop\plotting2.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 40, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "C:\Python27\lib\site-packages\matplotlib\axes\__init__.py", line 4, in <module>
from ._subplots import *
File "C:\Python27\lib\site-packages\matplotlib\axes\_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 23, in <module>
import matplotlib.dates as _ # <-registers a date unit converter
File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 130, in <module>
import dateutil.parser
File "C:\Python27\lib\site-packages\dateutil\parser.py", line 38, in <module>
from calendar import monthrange, isleap
ImportError: cannot import name monthrange
It looks like there may be a conflicting module named calendar. Are there any other packages (files) called "calendar" (calendar.py) in your python path? Try opening up a new python console and type from calendar import monthrange.
I have a Python code that works properly on my local machine. But when I run the same code on a remote cluster I get the following error:
Traceback (most recent call last):
from matplotlib import ticker as mtick # Import mtick for tick locating and formatting.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/ticker.py", line 158, in <module>
from matplotlib import transforms as mtransforms
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
The source of error is from matplotlib import ticker as mtick, but it works properly on my local machine. matplotlib version on both local and remote cluster is 1.4.3. Why does this error occur and how to fix it?
Update
When I comment that line I backend_pdf creates the following error:
from matplotlib.backends.backend_pdf import PdfPages # Import PDF matplotlib backend.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py", line 35, in <module>
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 45, in <module>
import matplotlib.transforms as transforms
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: /home/nxkr/.local/lib/python2.7/site-packages/matplotlib/_path.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
Commenting that causes pyplot to throw this error:
import matplotlib.pyplot as plt # Import matplotlib for plotting.
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/home/nxkr/.local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: /home/nxkr/.local/lib/python2.7/site-packages/matplotlib/_path.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
Why is that the same version of matplotlib is creating problems on different machines?
I am trying to plot a simple graph using python.
the code i used is as follows
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
It throws me an error called (Import Error : NO module called _path)
the error message is as follows.,
Traceback (most recent call last):
File "C:/Users/s siddharth kumar/Desktop/graph2.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\matplotlib\pyplot.py", line 26, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python27\lib\matplotlib\figure.py", line 24, in <module>
import matplotlib.artist as martist
File "C:\Python27\lib\matplotlib\artist.py", line 7, in <module>
from transforms import Bbox, IdentityTransform, TransformedBbox, \
File "C:\Python27\lib\matplotlib\transforms.py", line 35, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: No module named _path
Do i need to change the path of my running python in system variables or anything., ? I installed numpy,matplotlib and everything but still then I was not able to plot this simple values on the graph.
Please forgive my simple question. I have just started to use Matplotlib and I am having some difficulty.
I can run the following with the interpretor without problems:
>>> from pylab import *
>>> plot([1,2,3])
>>> show()
The above code generates a beautiful graph.
However, if I place the following code inside a file and run it, I get an error:
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
from pylab import *
plot([1,2,3])
show()
Here is the error message:
Traceback (most recent call last):
File "/Users/sbrown/Desktop/new1.py", line 12, in <module>
from pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 133, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py", line 15, in <module>
import new
File "/Users/sbrown/Desktop/new.py", line 2, in <module>
plot([1,2,3])
NameError: name 'plot' is not defined
>>>
Any idea what the problem could be? Thanks in advance for any help you can provide!
Looks like you have a file on your Desktop that is shadowing the standard Python new module:
>>> import new
>>> new
<module 'new' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/new.pyc'>
Rename or remove $HOME/Desktop/new.py and try again.