X11 Forwarding in PyCharm


I'm currently working on an object detection project, which I want to run on an Amazon EC2 over SSH with my MacBook Pro. The project works well locally, but when I run it over SSH I get "(Detector:5968): Gtk-WARNING **: cannot open display: " when I try to execute the line:

cv2.imshow('Detector', cv2.resize(image_np, (800, 600)))

I've tried to enable X11 Forwarding in the ssh_config-files, both locally and on the ec2. I've also tried to set the Display variable but I can't get it to work. What am I missing?


Unfortunately, PyCharm doesn't support X11 forwarding at this moment.

The related ticket from our issue tracking system https://youtrack.jetbrains.com/issue/PY-13869, please upvote and follow for updates.

You could try the workaround mentioned there: https://stackoverflow.com/questions/41892039/how-to-enable-x11-forwarding-in-pycharm-ssh-session


What worked for me was running "xhost +" in the terminal to disable access control and then starting an SSH session with the -X or -Y flag (leave it running). After that, X11 Forwarding worked in my PyCharm project with the correct Display variable set in Environment variables.


Please sign in to leave a comment.