'Cannot import matplotlib module after installing cython

To speed up certain resource-intensive Python functions, I'm using Cython. However, after using cython, I've seen that importing the matplotlib.pyplot module takes more than 2-3 minutes, whereas importing just "matplotlib" is instant. I'm guessing Cython messed up some matplotlib.pyplot operations. After importing matplotlib.pyplot if I hit ctrl+c I receive an error as

>>> import matplotlib.pyplot
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/raghvender/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2230, in <module>
    switch_backend(rcParams["backend"])
  File "/home/raghvender/.local/lib/python3.8/site-packages/matplotlib/__init__.py", line 672, in __getitem__
    plt.switch_backend(rcsetup._auto_backend_sentinel)
  File "/home/raghvender/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 225, in switch_backend
    current_framework = cbook._get_running_interactive_framework()
  File "/home/raghvender/.local/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 89, in _get_running_interactive_framework
    if not _c_internal_utils.display_is_valid():
KeyboardInterrupt

To me it appears that it is stuck in some cbook module. I tried removing cython module, reinstalling matplotlib but none of them worked. I'd appreciate it if someone could tell me where these two packages are interfering.

PS : I need Cython to perform some heavy calculation.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source