简体   繁体   中英

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). 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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