Unable to display output from matplotlib using conda through WSL

Viewed 234

I am trying to run ToPy (Topology Optimisation) program using anaconda on wsl. So, I created an environment with python-2.7 and all other programs recommended by ToPy.

I am running into an error with Display output from wsl to Xming. After some stressful debugging I came to the conclusion that matplotlib I installed on the anaconda environment is not supporting the output. (I initially thought its an error with Tkinter but it worked when I tried it on python-2.7 and python3, and I came to the conclusion that matplotlib is the issue after running a test code[below] on vscode using both python interpreters)

Test code: test.py

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)

plt.title('About as simple as it gets, folks')
plt.show()

This code works in wsl (not conda) and gave me an output. worked in conda with python3; gave me an output through XMing. But failed to give me output with python-2.7.15 I get this error:

Traceback (most recent call last):
  File "optimise.py", line 20, in <module>
    optimise(argv[1])
  File "optimise.py", line 16, in optimise
    topy.optimise(t)
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/topy/optimisation.py", line 67, in optimise
    _optimise(topology)
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/topy/optimisation.py", line 43, in _optimise
    create_2d_imag(t.desvars, **params)
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/topy/visualisation.py", line 56, in create_2d_imag
    figure() # open a figure
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/pyplot.py", line 533, in figure
    **kwargs)
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/site-packages/matplotlib/backends/_backend_tk.py", line 1046, in new_figure_manager_given_figure
    window = Tk.Tk(className="matplotlib")
  File "/home/sree/anaconda3/envs/py27/lib/python2.7/lib-tk/Tkinter.py", line 1819, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"

I checked with echo $DISPLAY returns :0.0 I tried xeyes and other output while in conda env with python-2.7.15; I get output through XMing but not the matplotlib plots.

I really need to finish this project soon; any help would be greatly appreciated.

TLDR; I use anaconda environment (with python-2.7.15) inside wsl and tried to run ToPy solver; Failed to get output only when working with matplotlib.

Sorry if I didn't word the question precisely; I recently started coding and am new to this forum.

1 Answers

For someone with a similar issue I got it to working with just a python update from 2.7.15 to 2.7.18

I did run conda install -c conda-forge r-tcltk2 It changed some conflicts and I got a glibcxx_3.4.26 not found error later but after updating linux distro and python to 2.7.18. I can run my simulations

Thanks a ton for prompt help

EDIT: This should help someone with installation issues

Related