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.
echo $DISPLAY, I get a local IP address. Did you try reinstalling this python version to see if that fixes it? Could you try your test code with some slightly different version?