简体   繁体   English

为X11转发配置macOS PyCharm

[英]Configuring macOS PyCharm for X11 Forwarding

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). 我正在尝试在远程计算机上的PyCharm中运行上面的简单代码,但是在我的本地计算机(mac)上显示了绘图。 The plot does not appear. 该图不出现。 I do have xQuartz X11 Server running. 我确实正在运行xQuartz X11 Server。 Pycharm runs the remote interpreter fine. Pycharm可以很好地运行远程解释器。

If I run it from macOS terminal, using 如果我从macOS终端运行它,则使用

ssh -X pier@129.168.0.181
python test.py

plt.show() works. plt.show()有效。

I reckon that the missing piece is the -X which enables the X11 to be forwarded to my local machine. 我认为缺少的部分是-X,它可以将X11转发到我的本地计算机。

Where do I include this with PyCharm's command to ssh? 我在哪里将PyCharm的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. 注意:我也无法使用PyCharm的Python控制台进行绘图。 No errors are shown but the plot is not forwarded to my local machine. 没有显示错误,但该图未转发到我的本地计算机。

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 (1)在Build,Execution,Deployment-> Python Console下的Environment Variables中设置DISPLAY = localhost:10.0

(2) Right after (2)之后

import matplotlib
matplotlib.use('Qt5Agg')

With this, I can use the remote interpreter as if it were local. 这样,我可以像使用本地解释器一样使用远程解释器。

Building of @Ippiers answer, on windows this works via: 在窗口上通过以下方式构建@Ippiers答案:

  1. install xming (and have it running) 安装xming(并使其运行)
  2. run a putty session with X11 forwarding enabled 在启用X11转发的情况下运行腻子会话
  3. env on the putty session and check the DISPLAY variable, it will probably be localhost:10.0 在腻子会话上启用env并检查DISPLAY变量,它可能是localhost:10.0
  4. Set this display variable in pycharms run configuration DISPLAY=localhost:10.0 在pycharms运行配置DISPLAY = localhost:10.0中设置此显示变量
  5. matplotlib.use('TkAgg') as Qt5 gave me errors matplotlib.use('TkAgg')因为Qt5给了我错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM