Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import with matplotlib 3.0.0 installed #58

Open
cYclonEK opened this issue Sep 20, 2018 · 9 comments
Open

Cannot import with matplotlib 3.0.0 installed #58

cYclonEK opened this issue Sep 20, 2018 · 9 comments

Comments

@cYclonEK
Copy link

C:\Users\enzok\AppData\Local\Programs\Python\Python36\python.exe D:/py_projs/every_day_task/test2.py
[INFO ] [Logger ] Record log in C:\Users\enzok.kivy\logs\kivy_18-09-20_37.txt
[INFO ] [Kivy ] v1.10.1
[INFO ] [Python ] v3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]
Traceback (most recent call last):
File "D:/py_projs/every_day_task/test2.py", line 1, in
from kivy.garden.matplotlib import *
File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\garden_init_.py", line 100, in load_module
return self.load_module(fullname, moddir)
File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\garden_init
.py", line 104, in _load_module
('', '', imp.PKG_DIRECTORY))
File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\imp.py", line 244, in load_module
return load_package(name, filename)
File "C:\Users\enzok\AppData\Local\Programs\Python\Python36\lib\imp.py", line 216, in load_package
return load(spec)
File "C:\Users\enzok.kivy\garden\garden.matplotlib_init
.py", line 1, in
from kivy.garden.matplotlib.backend_kivy import FigureCanvasKivy,
File "C:\Users\enzok.kivy\garden\garden.matplotlib\backend_kivy.py", line 257, in
from matplotlib.font_manager import weight_as_number
ImportError: cannot import name 'weight_as_number'

@mcu101
Copy link

mcu101 commented Sep 27, 2018

Hi, weight_as_number() was deprecated in matplotlib 2.1. I'm trying to develop a workaround by substituting the call to weight_as_number() in backend_kivy.py line 669 with an equivalent method that could be implemented completely within backend_kivy.py. This was weight_as_number()'s implementation:

def weight_as_number(weight): """ Return the weight property as a numeric value. String values are converted to their corresponding numeric value. """ if isinstance(weight, six.string_types): try: weight = weight_dict[weight.lower()] except KeyError: weight = 400 elif weight in range(100, 1000, 100): pass else: raise ValueError('weight not a valid integer') return weight

https://github.com/matplotlib/matplotlib/blob/0b604b3a57a62e70620aaf66756bb9233713a5a4/lib/matplotlib/font_manager.py

@mcu101
Copy link

mcu101 commented Sep 27, 2018

Ok, so I implemented weight_as_number() within backend_kivy.py but it seems like that not the only incompatibility with matplotlib 3.0.0. Running test_plt.py now gives the following error regarding matplotlib's backend_bases.py script:

`Traceback (most recent call last):
File "C:/Users/CarlosM/PycharmProjects/kivyplt/venv/test_plt.py", line 100, in
plt.show()
File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\pyplot.py", line 253, in show
return _show(*args, **kw)
File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\backend_bases.py", line 3300, in call
return self.show(block=block)
File "C:\Users\CarlosM\PycharmProjects\kivyplt\venv\lib\site-packages\matplotlib\backend_bases.py", line 3266, in show
cls.mainloop()
TypeError: mainloop() missing 1 required positional argument: 'self'

Process finished with exit code 1`

Out of curiosity, I changed matplotlib's backend_bases.py implementation to call cls.mainloop(self) with the self argument as suggested by the TypeError. But this time I got the error: NameError: name 'self' is not defined.

Any suggestions? Does anybody know more or less how much effort is needed to get the matplotlib Kivy flower to work with matplotlib 3.0.0? Would it be trivial?

@mcu101
Copy link

mcu101 commented Sep 27, 2018

By the way, it's still possible to get it to run on a virtual environment by installing matplotlib 2.0.0:

python -m pip install -U --force-reinstall matplotlib==2.0.0

@cYclonEK
Copy link
Author

Hello @mcu101
Thank you so much for your effort
I am just a beginner on these kivy and matplotlib things
Sorry that I cannot provide you more
Wish you good luck on this issue

@matham
Copy link
Member

matham commented Oct 9, 2018

Did #62 fix your issue?

@mcu101
Copy link

mcu101 commented Oct 10, 2018

@matham: I'll check it out in the next few days.

@tacaswell
Copy link

@mcu101 pip install 'matplotlib<3.0' is probably better so you will get the latest version of 2.2.

Did it ever get sorted out if this backend works with mpl >= 3.0?

@RobertFlatt
Copy link

Try this:

#from matplotlib import _png
#from matplotlib import _path

@Starosielec
Copy link

instead of altering kivy.garden code, this one works for me

import matplotlib
matplotlib._png = None
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants