问题
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:
- 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
来源:https://stackoverflow.com/questions/47765754/configuring-macos-pycharm-for-x11-forwarding