Configuring macOS PyCharm for X11 Forwarding

一曲冷凌霜 提交于 2021-01-21 05:48:04

问题


import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x = np.linspace(1,1000)
plt.plot(np.linspace(1, 1000))
print("Works")
plt.show()

I am trying to run the simple code above within PyCharm on a remote machine, but showing the plots on my local machine (mac). The plot does not appear. I do have xQuartz X11 Server running. Pycharm runs the remote interpreter fine.

If I run it from macOS terminal, using

ssh -X pier@129.168.0.181
python test.py

plt.show() works.

I reckon that the missing piece is the -X which enables the X11 to be forwarded to my local machine.

Where do I include this with PyCharm's command to ssh? I'm spending too much time trying to figure this out...

Note: I'm also not able to use PyCharm's Python Console to do plotting. No errors are shown but the plot is not forwarded to my local machine.


回答1:


Ok, I found I needed to do two things to get it working well enough for me :

(1) Set DISPLAY = localhost:10.0 in the Environment Variables under Build, Execution, Deployment -> Python Console

(2) Right after

import matplotlib
matplotlib.use('Qt5Agg')

With this, I can use the remote interpreter as if it were local.




回答2:


Building of @Ippiers answer, on windows this works via:

  1. install xming (and have it running)
  2. run a putty session with X11 forwarding enabled
  3. env on the putty session and check the DISPLAY variable, it will probably be localhost:10.0
  4. Set this display variable in pycharms run configuration DISPLAY=localhost:10.0
  5. matplotlib.use('TkAgg') as Qt5 gave me errors


来源:https://stackoverflow.com/questions/47765754/configuring-macos-pycharm-for-x11-forwarding

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