Can't use vscode remote with cv2.imshow: qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "..."

Viewed 9

I'm using vscode to connect to a server and I want to display an image with cv2.imshow() from openCV, but I get the following error:

debug1: client_input_channel_open: ctype x11 rchan 3 win 65536 max 16384
debug1: client_request_x11: request from 127.0.0.1 56848
connect localhost port 6000: Connection refused
debug1: failure x11
qt.qpa.xcb: could not connect to display localhost:10.0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/garro/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

When I connect via SSH i get the following warning:

Warning: No xauth data; using fake authentication data for X11 forwarding.

and when I try to open xclock app:

debug1: client_input_channel_open: ctype x11 rchan 3 win 65536 max 16384
debug1: client_request_x11: request from 127.0.0.1 55428
connect localhost port 6000: Connection refused
debug1: failure x11
Error: Can't open display: localhost:10.0

Also, as suggested in many posts about the topic, I added the following lines to /etc/ssh/ssh_config on my mac:

Host *
    ForwardX11Trusted yes
    ForwardAgent yes
    ForwardX11 yes
    XAuthLocation /opt/X11/bin/xauth

and added the DISPLAY env variable:

export $DISPLAY=localhost:0

On the server:

  • sudo apt install xauth

  • I enabled X11Forwarding yes and changed the line #AddressFamily any to AddressFamily inet on the /etc/ssh/sshd_config file.

  • sudo service ssh restart

  • to generate the Xauthority file on the server:

    touch ~/.Xauthority

    xauth add :0 . mcookie

for helping debugging, this is the output of the ssh command with -v flag:

OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/federico/.ssh/config
debug1: /Users/federico/.ssh/config line 15: Applying options for pod
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 27: Applying options for *
debug1: /etc/ssh/ssh_config line 55: Applying options for *
debug1: /etc/ssh/ssh_config line 59: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to localhost port 2222.
debug1: Connection established.
debug1: identity file /Users/federico/.ssh/id_rsa type 0
debug1: identity file /Users/federico/.ssh/id_rsa-cert type -1
debug1: identity file /Users/federico/.ssh/id_dsa type -1
debug1: identity file /Users/federico/.ssh/id_dsa-cert type -1
debug1: identity file /Users/federico/.ssh/id_ecdsa type -1
debug1: identity file /Users/federico/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/federico/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/federico/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/federico/.ssh/id_ed25519 type -1
debug1: identity file /Users/federico/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/federico/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/federico/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/federico/.ssh/id_xmss type -1
debug1: identity file /Users/federico/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.5 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:2222 as 'garro'
debug1: load_hostkeys: fopen /Users/federico/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: Permission denied
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:wrtmOmumGwo+oUIuyPBiVkHXwFzskbFS7XTcZEAqLMY
debug1: load_hostkeys: fopen /Users/federico/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: Permission denied
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '[localhost]:2222' is known and matches the ED25519 host key.
debug1: Found key in /Users/federico/.ssh/known_hosts:25
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/federico/.ssh/id_rsa RSA SHA256:4M2MS6WXGh13cFPcjJgUOsbQi85gof+ibMj79waAN60
debug1: Will attempt key: /Users/federico/.ssh/id_dsa
debug1: Will attempt key: /Users/federico/.ssh/id_ecdsa
debug1: Will attempt key: /Users/federico/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/federico/.ssh/id_ed25519
debug1: Will attempt key: /Users/federico/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/federico/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/federico/.ssh/id_rsa RSA SHA256:4M2MS6WXGh13cFPcjJgUOsbQi85gof+ibMj79waAN60
debug1: Server accepts key: /Users/federico/.ssh/id_rsa RSA SHA256:4M2MS6WXGh13cFPcjJgUOsbQi85gof+ibMj79waAN60
debug1: Authentication succeeded (publickey).
Authenticated to localhost ([::1]:2222).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: exec
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/federico/.ssh/known_hosts for [localhost]:2222 / (none)
debug1: client_input_hostkeys: searching /Users/federico/.ssh/known_hosts2 for [localhost]:2222 / (none)
debug1: client_input_hostkeys: hostkeys file /Users/federico/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: Remote: /home/garro/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /home/garro/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Warning: No xauth data; using fake authentication data for X11 forwarding.
debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: channel 0: setting env LC_TERMINAL_VERSION = "3.4.16"
debug1: channel 0: setting env LC_TERMINAL = "iTerm2"
debug1: channel 0: setting env LC_CTYPE = "UTF-8"
Last login: Fri Sep 23 22:03:40 2022 from 127.0.0.1.

I know that is possible to save each image cv2.imwrite(), but in my case I'm doing some complex debugging and I cannot save every single image. I really need to do it this way. Also, I know that there are many post on the topic, but after trying the suggested solutions above, I still can't make it work. What am I missing?

I'm using macOS Monterrey 12.5.1

Any suggestions on what else to try? Thanks for your help!! :)

0 Answers
Related