问题描述
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()
我试图在远程机器上的 PyCharm 中运行上面的简单代码,但在我的本地机器 (mac) 上显示图.剧情没有出现.我确实运行了 xQuartz X11 服务器.Pycharm 可以很好地运行远程解释器.
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.
如果我从 macOS 终端运行它,使用
If I run it from macOS terminal, using
ssh -X [email protected]
python test.py
plt.show() 有效.
plt.show() works.
我认为缺少的部分是 -X,它使 X11 能够转发到我的本地机器.
I reckon that the missing piece is the -X which enables the X11 to be forwarded to my local machine.
在 PyCharm 的 ssh 命令中我应该在哪里包含它?我花了太多时间试图解决这个问题...
Where do I include this with PyCharm's command to ssh? I'm spending too much time trying to figure this out...
注意:我也无法使用 PyCharm 的 Python 控制台进行绘图.未显示任何错误,但该图未转发到我的本地机器.
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.
推荐答案
@Ippiers 答案的构建,在 Windows 上通过:
Building of @Ippiers answer, on windows this works via:
- 安装 xming(并让它运行)
- 在启用 X11 转发的情况下运行 Putty 会话
- 在 putty 会话中使用 env 并检查 DISPLAY 变量,它可能是 localhost:10.0
- 在pycharms运行配置中设置这个显示变量DISPLAY=localhost:10.0
matplotlib.use('TkAgg')
因为 Qt5 给了我错误
- install xming (and have it running)
- run a putty session with X11 forwarding enabled
- env on the putty session and check the DISPLAY variable, it will probably be localhost:10.0
- Set this display variable in pycharms run configuration DISPLAY=localhost:10.0
matplotlib.use('TkAgg')
as Qt5 gave me errors
这篇关于为 X11 转发配置 macOS PyCharm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!