how can I enable x-11 forwarding in pycharm? when connecting to vagrant or a remote ssh?

白昼怎懂夜的黑 提交于 2019-12-04 11:30:12

问题


I am using pycharm in windows but the python backend need to be running on unix so I host the python app/code in ubuntu with vagrant, however I need to do some plotting as well, is there a way I can enable matplotlab plotting in pycharm with vagrant? thanks


回答1:


Try to set DISPLAY environment variable in PyCharm run configuration like this:

DISPLAY=localhost:10.0

I got my display value from vagrant ssh connection

vagrant@vagrant:$ echo $DISPLAY
localhost:10.0



回答2:


In case anyone stumbles upon the same issue.. There are several ways for you to enable X11 through PyCharm.

The solution for me was to create a terminal session using the -Y flag (or -X), e.g.:

ssh -X user@ip

or

ssh -Y user@ip

The -Y worked for me as it enables trusted X11 forwarding, which are not subjected to X11 Security extension controls (ssh man page)

You also need to export DISPLAY variable just like user138180 said

For me the matplotlib backend that worked was "tkagg". See matplotlib faq for more info.


My remote machine is a centos 7. My local machine is running Manjaro.

A workaround to having the terminal session opened is to follow what Tarun said here.


As an example, (thanks, user138180), you could use this code to test if it works:

import matplotlib matplotlib.use('TkAgg')
import matplotlib.pyplot as plt plt.interactive(False)

plt.hist(np.random.randn(100))
plt.show()


来源:https://stackoverflow.com/questions/30813370/how-can-i-enable-x-11-forwarding-in-pycharm-when-connecting-to-vagrant-or-a-rem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!