Windows Subsystem for Linux#

This page shows you how to use a PyAnsys library, more specifically PyMAPDL, in the Windows Subsystem for Linux (WSL). WSL is a compatibility layer for running Linux binary executables natively on Windows 10, Windows 11, and Windows Server 2019. For more information, see Wikipedia WSL.

Sections on this page walk you through the installation of WSL on Windows and then show how to use it together with MAPDL, PyMAPDL, and Docker.

For more information about WSL, see What is the Windows Subsystem for Linux.


This approach hasn’t been fully tested with a VPN connection. If you experience any problems connecting WSL to the internet, try to disconnect from the VPN.


Install WSL#

Install WSL by following Microsoft’s directions at Microsoft: Install WSL.

Currently there are two versions of WSL: WSL1 and WSL2. Because WSL2 is the latest and includes many improvements over WSL1, using WSL2 is highly recommended.

Install CentOS 7 WSL distribution#

Install CentOS 7 WSL distribution#

You should use the CentOS 7 WSL distribution for working with PyAnsys libraries.

You can install it using an unofficial WSL distribution from CentOS-WSL or CentOS WSL .

Optionally, you can try Ubuntu, but it has not been tested yet in the context of WSL.

Install Ansys products in WSL CentOS 7#


If you are using CentOS 7, before installing MAPDL, you must install some required libraries:

sudo yum install openssl openssh-clients mesa-libGL mesa-libGLU motif libgfortran

If you are using Ubuntu, follow the instructions in Run MAPDL: Ubuntu .

Install Ansys products#

To install Ansys products in WSL Linux:

  1. Download the Ansys Structures image from the customer portal (Current Release). If you are downloading the image on a Windows machine, you should later copy it from you downloads folder to WSL.

  2. Decompress the source code file (tar.gz) with:

    tar xvzf STRUCTURES_2021R2_LINX64.tgz
  3. To install MAPDL, go into the uncompressed folder and type:

    sudo ./INSTALL -silent -install_dir /usr/ansys_inc/ -mechapdl


    • -silent : Initiates a silent installation (no GUI).

    • -install_dir /path/ : Specifies the directory to which the product or license manager is to be installed. If you want to install to the default location, you can omit the -install_dir argument. The default location is /ansys_inc if the symbolic link is set. Otherwise, it defaults to /usr/ansys_inc.

    • -<product_flag> : Specifies one or more specific products to install. If you omit this argument, all products are installed. See the list of valid product flags in Chapter 6 of the ANSYS Inc. Installation Guides PDF. In this case, only MAPDL (-mechapdl) is needed.

After installing MAPDL directly in /ansys_inc or in /usr/ansys_inc, create a symbolic link with:

sudo ln -s /usr/ansys_inc /ansys_inc

By default, PyMAPDL expects the MAPDL executable to be in /usr/ansys_inc. Whether you install it there or not, you should link that directory, using a symbolic link, to your Ansys installation directory (/*/ansys_inc).

Post-installation setup#

Open ports#

Theory: You should open the ports 1055 and 2325 for the license server communication in Windows Firewall Advanced. You can see the steps in How to open port in Windows 10 Firewall.

Reality: This works if you want to run a Docker image using WSL Linux image to host that Docker image. The Docker image successfully communicates with the Windows License Server using these ports if you use the '-p' flag when running the Docker image and these ports are open. For more information, see Run an MAPDL image <run_an_mapdl_image_>.

If you want to run MAPDL in the CentOS 7 image and use the Windows license server, opening the ports might not work properly because the Windows firewall seems to block all traffic coming from WSL. For security purposes, you should still try to open ports 1055 and 2325 in the firewall and see if your MAPDL installation can communicate with the Windows hosts. If you are having problems after setting the firewall rules, you might have to turn off the Windows firewall for the WSL ethernet virtual interface. This might pose some unknown side effects and security risk so use it with caution. See Disabling Firewall on WSL Ethernet.

Set up an environmental variable in WSL that points to Windows host license server#

The Windows host IP address is given in the WSL file /etc/hosts before the name host.docker.internal.


This host.docker.internal definition might not be available if Docker is not installed.

Example /etc/hosts/ file

# This file was automatically generated by WSL.
# To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false       localhost   AAPDDqVK5WqNLve    host.docker.internal    gateway.docker.internal       kubernetes.docker.internal

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

You can add the next lines to your WSL ~/.bashrc file to create an environment variable with this IP address:

winhostIP=$(grep -m 1 host.docker.internal /etc/hosts | awk '{print $1}')
export ANSYSLMD_LICENSE_FILE=1055@$winhostIP

Launch MAPDL in WSL#

To launch MAPDL in WSL, you must follow the procedure in Launch a gRPC MAPDL session <launch_grpc_madpl_session_>. An example follows.

/ansys_inc/v222/ansys/bin/ansys222 -grpc

This launches an MAPDL instance whose working directory is the current directory. If you want to change the working directory, you can use the -dir flag.

/ansys_inc/v222/ansys/bin/ansys222 -grpc -dir /tmp/ansys_jobs/myjob

Connect to an MAPDL instance running in WSL#

To connect to the WSL instance that is running the MAPDL instance, follow the procedure in Connect to the MAPDL container from Python <pymapdl_connect_to_MAPDL_container_> but specify the IP address of the WSL instance:

from ansys.mapdl.core import Mapdl

mapdl = Mapdl(ip='', port=50053)


The specified IP address in Run an MAPDL image <run_an_mapdl_image_> is the IP address of WSL CentOS from the WSL perspective, whereas the Windows host IP address is normally Docker builds the PyMAPDL images using the WSL distribution as the base. Hence, PyMAPDL is running on a Linux WSL distribution, which is running on a Windows host. Because the Docker image shares resources with WSL, it also shares the internal IP address with the WSL distribution.

Additional notes#

Other Ansys installation flags#

You can obtain license server information with one of the following, inspecting the last lines of the INSTALL file:

./INSTALL --help




Specifies information to be used by the client for the license server. Valid only in conjunction with a silent installation (INSTALL).

The format for a single license server is:

-licserverinfo LI_port_number:FLEXlm_port_number:hostname


./INSTALL -silent -install_dir /ansys_inc/ -mechapdl -licserverinfo 2325:1055:winhostIP

The format for three license servers is:

-licserverinfo LI_port_number:FLEXlm_port_number:hostname1,hostname2,hostname3


./INSTALL -silent -install_dir /ansys_inc/ -mechapdl -licserverinfo 2325:1055:abc,def,xyz


Specifies a language to use for the installation of the product.


You can specify an options file that lists the products that you want to install. To do so, you must provide a full path to the file containing the products to install.

IP addresses in WSL and the Windows host#


You should be able to access the Windows host using the IP address specified in /etc/hosts, which normally is This means that the local WSL IP address is


It is almost impossible to use for connecting to the Windows host. However, it is possible to use the host.docker.internal hostname in the same file (/etc/hosts). This is an IP address that is randomly allocated, which is an issue when you define the license server. However, if you update .bashrc as mentioned earlier, this issue is solved.

Disable firewall on WSL ethernet#

This method shows a notification:

Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"

This method does not show a notification:

powershell.exe -Command "Set-NetFirewallProfile -DisabledInterfaceAliases \"vEthernet (WSL)\""

Link: Disabling Firewall on WSL Ethernet

Windows 10 port forwarding#

PowerShell command to view all forwards#

netsh interface portproxy show v4tov4

Delete port forwarding#

netsh interface portproxy delete v4tov4 listenport=1055 listenaddres= protocol=tcp

Reset Windows network adapters#

netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
netsh winsock reset

Restart WSL service#

Get-Service LxssManager | Restart-Service

Kill all processes with a given name#

Get-Process "ANSYS212" | Stop-Process

Install xvfb in CentOS 7#

If you want to replicate the CI/CD behavior, xvfb is needed. For more information, see the .ci folder.

yum install xorg-x11-server-Xvfb


  • PyMAPDL only works for shared-memory parallel (SMP) when running on WSL. This is why the flag -smp should be included.

  • Because there are some incompatibilities between VPN and INTEL MPI, use the flag -mpi msmpi when calling MAPDL.