X11Error: Can't open display on Windows

I am getting this message when trying to start AFNI:

Initializing: X11Error: Can’t open display:
++ AFNI is detached from terminal.

Any ideas how to fix it?

Story behind:
AFNI Installed on Win10/WSL/Ubuntu a few months ago, without major problems (there was a dependency problem with encryption libraries, but good linux-knowing people helped me solve it)
I’ve been using AFNI since then, not very frequently, but usually keeping it open all the time (this is because in my hands AFNI loses most tweaks/settings between sessions, like data directories, added palettes, smoothing params, etc)
I’ve been alternating between using it locally and remotely, the latter via Windows Remote Destop from an off-campus location.

Last Wednesday, while AFNI was open, the machine restarted (probably a brief power outage).
I connected to it remotely, and AFNI would not start at all. When I typed afni it would say Command not found. Same when I tried to run AFNI update.
I ran AFNI install (remotely) and now it reports the X11Error as shown at the top.
I reinstalled VcXsrv Windows X Server, but nothing has changed.
I googled for answers and found posts that suggested that starting things remotely may be a problem (though the posts were about AFNI on Macs, so maybe not pertinent).
I went to the lab and started XLaunch and then AFNI locally, got the same error. Restarted the machine, tried again, same thing.

Can anyone help me please? (Side note, I know virtually nothing about linux, so please be very clear with instructions)

Hi, Pawel-

What version of linux do you have? That is, what is the output of:


lsb_release -a

Note that you can preserve your tailorings (though, I’m not sure by what you mean as your “smoothing” in the AFNI GUI?) by setting values in teh ~/.afnirc file. As part of the installation instructions, these can be initially created during installation as described here:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/background_install/install_instructs/steps_linux_ubuntu18.html#make-afni-suma-profiles
… and then you can edit it further; the descriptor help for AFNI environment variables is here:
https://afni.nimh.nih.gov/pub/dist/doc/program_help/README.environment.html

I don’t know what a power outage would have done/changed. For starters, what is your PATH on the machine:


echo $PATH

And what is your display:


echo $DISPLAY

Note that you have click on the VcXsrv Windows X Server icon each time before starting your Linux terminal-- that is just how Windows designed things for allowing X-stuff through the terminal.

–pt

ptaylor Wrote:

What version of linux do you have? That is, what
is the output of:
lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial

Note that you can preserve your tailorings
(though, I'm not sure by what you mean as your
"smoothing" in the AFNI GUI?) by setting values in
teh ~/.afnirc file.

Thank you, I'll look into it. I have some options saved there, like orientation. I forgot what the actual name of that smoothing option is in GUI (and having no access to AFNI, I can't check!) , maybe it's resampling, the visual effect is smoothing of activation overlay, options are NN(nearest neighbor), linear and more.

I don't know what a power outage would have
done/changed. For starters, what is your PATH on
the machine:
echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program:Files:(x86)/Common:Files/Intel/Shared:Files/cpp/Bin/Intel64:/mnt/c/Program:Files:(x86)/Intel/iCLS:Client:/mnt/c/Program:Files/Intel/iCLS:Client:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Program:Files:(x86)/Intel/Intel(R):Management:Engine:Components/DAL:/mnt/c/Program:Files/Intel/Intel(R):Management:Engine:Components/DAL:/mnt/c/Program:Files:(x86)/Intel/Intel(R):Management:Engine:Components/IPT:/mnt/c/Program:Files/Intel/Intel(R):Management:Engine:Components/IPT:/mnt/c/Program:Files/MATLAB/R2017b/bin:/mnt/c/Program:Files/MATLAB/R2016a/bin:/mnt/c/Windows/System32/OpenSSH:/mnt/c/FPC/3.0.4/bin/i386-win32:/mnt/c/Users/pawel/AppData/Local/Microsoft/WindowsApps:/home/pawel/abin

This is weird, why would Linux have my windows matlab in the path? Anyway, does not matter really.

And what is your display:
echo $DISPLAY

DISPLAY: Undefined variable.

(though at this point I can only use this machine remotely, I can re-check DISPLAY locally on Monday)

Note that you have click on the VcXsrv Windows X
Server icon each time before starting your Linux
terminal-- that is just how Windows designed
things for allowing X-stuff through the terminal.

Yes, I remember to always do this!

Well, you do have the AFNI binary directory in your $PATH, so that is good.

Re. the $DISPLAY variable, can you copy+paste the following into the Ubuntu terminal:


echo "export DISPLAY=:0.0" >> ~/.bashrc
echo "setenv DISPLAY :0.0" >> ~/.cshrc
echo "export NO_AT_BRIDGE=1" >> ~/.bashrc
echo "setenv NO_AT_BRIDGE 1" >> ~/.cshrc

and open a new terminal. In that new terminal, what does:


echo $DISPLAY

do?

–pt

ptaylor Wrote:

Re. the $DISPLAY variable,
what does:
echo $DISPLAY
do?

:0.0

This is still remotely, again, I can recheck locally on Monday

Well, I can say it started to work again somehow.

The X server needs to be started before starting Ubuntu.
Maybe you did that this time.

  • rick

Yes I know and I am pretty sure I did it before as well.

I am reviving this thread because I ran into the same problem though in a new installation and under different circumstances.

So I just installed AFNI on a windows computer, using instructions from
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/background_install/install_instructs/steps_windows10.html
and
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/background_install/install_instructs/steps_linux_ubuntu18.html#install-steps-linux-ubuntu18

The installation went kind of OK, bdrm would not install despite trying the suggested fix (If you are using Windows Subsystem Linux (WSL), and/or if your ‘brms’ package fails to install (as checked in the “Evaluation” step below)…), but I googled around, tried other solutions, and ultimately
afni_system_check.py -check_all said:


=========================  summary, please fix:  =========================
*  just be aware: login shell 'bash', but our code examples use 'tcsh'

But if I try:
afni

I get


Precompiled binary linux_ubuntu_16_64: Nov 12 2020 (Version AFNI_20.3.02 'Vespasian')


** Version check disabled: AFNI_VERSION_CHECK forbids
Thanks go to MM Klosek for inspiration

Initializing: X11Error: Can't open display: :0.0
++ AFNI is detached from terminal.

[size=large]And yes I did start VcXsrv \ XLaunch prior to starting Ubuntu.[/size]

Here is other possibly relevant info:

Windows


Microsoft Windows 10 Enterprise 10.0.20262 Build 20262

wsl --status


Default Distribution: Ubuntu-18.04
Default Version: 2
Windows Subsystem for Linux was last updated on 11/26/2020
Kernel version: 5.4.72

lsb_release -a


No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:        18.04
Codename:       bionic

I did run


echo "export DISPLAY=:0.0" >> ~/.bashrc
echo "setenv DISPLAY :0.0" >> ~/.cshrc
echo "export NO_AT_BRIDGE=1" >> ~/.bashrc
echo "setenv NO_AT_BRIDGE 1" >> ~/.cshrc

and closed Ubuntu terminal afterwards (also restarted the computer)

$ echo $DISPLAY


:0.0

echo $PATH


/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2020.824.0_x64__79rhkp1fndgsc:/mnt/c/Program Files/Python38/Scripts/:/mnt/c/Program Files/Python38/:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/ProgramData/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Common Files/Intel/Shared Files/cpp/bin/Intel64:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/Program Files/MATLAB/R2020a/bin:/mnt/c/Program Files/MATLAB/R2019a/bin:/mnt/c/Program Files/MATLAB/R2019a/bin/win64:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Users/Pawel/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Pawel/AppData/Local/Microsoft/WindowsApps:/snap/bin:/home/pawel/abin

I would be grateful for any suggestions how to fix it.

I also have an unrelated question:
The instructions for installing AFNI on windows only mention Ubuntu 16.04 and 18.04. But after I installed specifically Ubuntu 18.04 and AFNI, I saw that you are also providing instructions for installing AFNI on Ubuntu 20.04. Is there any reason why one should not install AFNI on Ubuntu 20.04 on Windows/WSL - or is it just an oversight and the link to 20.04 instructions has not been added to Windows instructions?

P.S. funny I am posting exactly 2 years after the previous post in the thread

wsl 2, the version you are running, makes the X11 display configuration harder, but it works. I have included some notes on this, but you can also consider switching to wsl version 1, where the X11 configuration was simpler.

X11 server had some problems. VcxSrv worked with the following changes (Native opengl off, Disable access control on). The settings can be saved as an XLaunch configuration to the Desktop and launched from the configuration for future starts.

Also must set DISPLAY in Ubuntu terminal. This is different from WSL1.
export DISPLAY=“$(/sbin/ip route | awk ‘/default/ { print $3 }’):0”

The /sbin/ip router seems more reliable than the “dig” command method that is also posted elsewhere. The same IP address that gets used also appears in the output of “ipconfig.exe” (DOS style name in Linux is strange) in the Ubuntu terminal.
Wireless LAN adapter Wi-Fi:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : xxx
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter Bluetooth Network Connection:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Ethernet adapter vEthernet (WSL):

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : xxx
IPv4 Address. . . . . . . . . . . : xxx.xx.xxx.xx
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . :

So this command should work too using that output:
export DISPLAY=$(ipconfig.exe |grep -A 4 WSL | tail -1 | awk -F: ‘{print $2}’|tr -d ‘[:space:]’):0

X11 seems very slow to start here, but works okay when it starts. suma doesn’t seem to work as well with VcxSrv though.

MobaXterm seems a little faster, and suma works pretty well. It now requires some babying, instead of working just out of the box. And it requires accepting in a couple windows connections across the virtual network adapter from the WSL side into the Windows side.
export DISPLAY=“$(/sbin/ip route | awk ‘/default/ { print $3 }’):0”

Click “Yes” to accept. Note the IP address in the message is different from both the previous ones used here. To avoid this warning message, do as the window says and change MobaXterm settings and set X11 remote access to full instead of “on-demand”.

Also another note, once MobaXterm starts, it acts as an Xserver too. Even Ubuntu terminal shells can use this with similar DISPLAY settings.

I expect that a couple other Xservers will work too - Xwin32, X410.

Some related links:
https://www.reddit.com/r/bashonubuntuonwindows/comments/heforb/issue_with_wsl2_and_gui_apps/
https://x410.dev/cookbook/wsl/using-x410-with-wsl2/

Thank you, Daniel. Much of your response is completely cryptic to a Windows simpleton like me :slight_smile:

I tried the initial part, (export DISPLAY=“$(/sbin/ip route | awk ‘/default/ { print $3 }’):0”) plus changing VcxSrv options, but that got me nowhere.

So I switched to WSL 1 and both AFNI and SUMA GUIs start fine. Thanks a lot!

Good to hear you figured out something. While performance is slightly better, the WSL2 version did make things more complicated unfortunately, but it looks like it will eventually be a better configuration for everyone with more native support for graphics.