2

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.

14
  • Hmm, I can't reproduce your problem. I have WSL2, Ubuntu 20.04, and I'm using MobaXTerm. I installed the miniconda-latest using pyenv (python 2.7.18), installed matplotlib with conda, then ran your code, with Qt and Tkinter, and both outputted ok. When I use 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? Commented Mar 28, 2021 at 2:01
  • I can't actually. The ToPy libraries use python-2.7. was suggested against updating. you got an output of a sine curve with python-2.7? Commented Mar 28, 2021 at 2:02
  • No, I mean a different python 2.7, like 2.7.18, that shouldn't mess anything with the code. Or a completely new environment, installed from scratch. Then again, do you need to see the output? Can't you suppress showing it, and look at a saved image? Commented Mar 28, 2021 at 2:04
  • Oh, and yes, I got the sine curve with python 2.7 Commented Mar 28, 2021 at 2:06
  • 1
    OMG THANK YOU SO SO MUCH Finally I got the results on ToPy Commented Mar 28, 2021 at 2:44

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.