'from yade import plot' causing error

Asked by Harsh Patel

I recently re-installed the current version of YADE on my Ubuntu 18.04 and ran the simple Gravity Desposition program (given here https://yade-dem.org/doc/tutorial-examples.html) and I am getting the following error:
~/Dropbox/Lit review/INDOT project/programs$ yade trial.py
Welcome to Yade 2018.02b
TCP python prompt on localhost:9000, auth cookie `ydcuae'
XMLRPC info provider on http://localhost:21000
Running script trial.py
Traceback (most recent call last):
  File "/usr/bin/yade", line 182, in runScript
    execfile(script,globals())
  File "trial.py", line 6, in <module>
    from yade import pack, plot
  File "/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py", line 25, in <module>
    import matplotlib,os,time,math,itertools
  File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 127, in <module>
    from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/usr/lib/python2.7/dist-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/usr/lib/python2.7/dist-packages/matplotlib/fontconfig_pattern.py", line 32, in <module>
    from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache

***************
I didn't get this error on my previous ubuntu 16. Also, when I remove the plot function (and its corresponding calls in my program), the error doesn't come and the program runs smoothly as before. Can someone let me know the problem (probably with the calling of plot function)?

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Harsh Patel
Solved:
Last query:
Last reply:
Revision history for this message
Jérôme Duriez (jduriez) said :
#1

Hi,

For the record, there are no functions to blame here : the problem arises when you "import plot" (as you should see if you just type this in your YADE terminal), which is importing the YADE *module* "plot"
(this module defines functions such as plot.plot() )

Going further (following what the error says) the error comes from a failed "import matplotlib", that is called by the "import plot", where matplotlib is an external Python module, not provided by YADE.

In the end, I think you would get the same error typing "import matplotlib" in your YADE terminal, which is a (2.7) Python terminal, and your question should be entitled "import matplotlib error" ;-)

Looking through the Internet for similar errors (in the general Python community) gives things like e.g. [*]. Maybe they can help...
(I do not know the answer myself even though I hope I could make the situation clearer...)

[*] https://stackoverflow.com/questions/50150952/cannot-import-matplotlib-after-update-to-ubuntu-18-04-due-to-missing-functools

Revision history for this message
Harsh Patel (j0hnn1e) said :
#2

Hello Jerome, Thank you for replying. Firstly, I changed the title of the question as told by you. Secondly, I followed all the troubleshooting methods explained in this post (https://stackoverflow.com/questions/47179433/python-2-7-functools-lru-cache-does-not-import-although-installed/49335954#49335954) but I am still getting the same error:
----------------------------------------------------------
In [1]: from yade import plot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/usr/bin/yade in <module>()
----> 1 from yade import plot

/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in <module>()
     23
     24
---> 25 import matplotlib,os,time,math,itertools
     26
     27 # running in batch

/usr/lib/python2.7/dist-packages/matplotlib/__init__.py in <module>()
    125 _backports, mplDeprecation, dedent, get_label, sanitize_sequence)
    126 from matplotlib.compat import subprocess
--> 127 from matplotlib.rcsetup import defaultParams, validate_backend, cycler
    128
    129 import numpy

/usr/lib/python2.7/dist-packages/matplotlib/rcsetup.py in <module>()
     27
     28 from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper
---> 29 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
     30 from matplotlib.colors import is_color_like
     31

/usr/lib/python2.7/dist-packages/matplotlib/fontconfig_pattern.py in <module>()
     30 from functools import lru_cache
     31 except ImportError:
---> 32 from backports.functools_lru_cache import lru_cache
     33
     34 family_punc = r'\\\-:,'

ImportError: No module named functools_lru_cache
-------------------------------------------
Any help to troubleshoot this would be appreciated. I am not able to use YADE because of this for quite a long time.

Revision history for this message
Harsh Patel (j0hnn1e) said :
#3

Hello all, this answer did the trick for me (https://stackoverflow.com/a/47317710/4365590).