2

I'm recently trying to do something with Tensorflow. The installation seems very fine until I've encountered this problem. When importing matplotlib.pyplot, AttributeError was thrown. Below is the detail:

>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/syine/venv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2349, in <module>
    switch_backend(rcParams["backend"])
  File "/home/syine/venv/lib/python3.7/site-packages/matplotlib/__init__.py", line 820, in __getitem__
    plt.switch_backend(rcsetup._auto_backend_sentinel)
  File "/home/syine/venv/lib/python3.7/site-packages/matplotlib/pyplot.py", line 212, in switch_backend
    newbackend[9:] if newbackend.startswith("module://")
AttributeError: 'object' object has no attribute 'startswith'

Seemingly it's an internal error in the module, however I can't find any hint to solve the issue.

I tried reinstalling matplotlib and all of its dependencies (FreeType, libpng, NumPy, setuptools, cycler, dateutil, kiwisolver, pyparsing), but none of them could solve the problem.

4
  • does from matplotlib import rcParams, rcParamsDefault, get_backend, rcParamsOrig work without errors? it seems that newbackend is no string, hence it has no 'startswith' method Commented May 23, 2019 at 7:44
  • 1
    @jww What I've uploaded is everything which causes the problem. Just importing a module throws an exception. Should I upload every pyplot code that I use? Commented May 23, 2019 at 7:53
  • 1
    what does matplotlib.rcsetup.all_backends print you out? (you have to do import matplotlib.rcsetup first) Commented May 23, 2019 at 9:50
  • 1
    This is a strange error. Can you provide information about how you run this code (which kind of interpreter, CLI etc.), your operating system and your matplotlib version (import matplotlib; print(matplotlib.__version__). How exactly did you install matplotlib. Also what does print(matplotlib.rcParams["backend"]) result in? Commented May 23, 2019 at 10:33

2 Answers 2

3

Looks like this is a known issue:

https://github.com/matplotlib/matplotlib/issues/14263

It sounds like it may be a problem with your environment and the fix in GitHub will only serve to raise a meaningful error message

Sign up to request clarification or add additional context in comments.

1 Comment

Good point! I think the one guy updated pillow, numpy and scipy, then he was able to load the backends
-2

Use the function hasattr this will let you check whether a particular attribute belongs to a object or not before referencing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.