How to get Pytorch Working in Fedora 40 with WSL2

Swift Tree Data Solutions

Install WSL2: Ensure you have WSL2 installed and set up on your Windows machine. You can follow the official Microsoft guide to install WSL2.

Install Fedora 40: If you haven’t already installed Fedora 40, you can do so using the following command:

wsl --install -d fedora

Enable Systemd: By default, WSL2 doesn’t use systemd. However, you can enable it with some modifications.

sudo dnf install -y systemd systemd-sysv systemd-libs

Create a Script to Launch Systemd: Create a script that will start systemd when your WSL2 session starts. You can name this script

export WSL_DISTRO_NAME=$(basename $(cat /etc/os-release | grep '^NAME=' | cut -d '"' -f 2))
if [ "$WSL_DISTRO_NAME" == "Fedora" ]; then
  exec sudo /usr/sbin/init

Make the script executable:

sudo chmod +x /usr/local/bin/

To get to your %UserProfile% directory, in PowerShell, use cd ~ to access your home directory (which is typically your user profile, C:\Users\<UserName>) or you can open Windows File Explorer and enter %UserProfile% in the address bar. The directory path should look something like: C:\Users\<UserName>\.wslconfig.

in the WSL config, run these configurations:


Step 2: Setup Systemd in Fedora on WSL2

Create a Systemd ScriptOpen your Fedora WSL2 terminal and create a script to start systemd:

sudo nano /usr/sbin/enter-systemd-namespace

Add the following content to the script:


if test -n "$WSL_INTEROP"; then
    export WSL_INTEROP
    /usr/bin/nsenter -m -u -i -n -p -t 1 sudo /usr/sbin/init

exec /usr/bin/nsenter -m -u -i -n -p -t 1 "$@"

Save and close the file.

Make the Script Executable

Make the script executable:

sudo chmod +x /usr/sbin/enter-systemd-namespace

Modify your Shell configuration

if test -z "$WINDOWS_PATH"; then
    WINDOWS_PATH=$(wslpath "$(wslvar PATH)")

alias sudo='sudo env "PATH=$WINDOWS_PATH"'
alias systemctl="sudo /usr/sbin/enter-systemd-namespace systemctl"

Source your shell configuration to apply the changes:

source ~/.bashrc

Install Cockpit and its dependencies:

sudo dnf install -y cockpit cockpit-podman
sudo /usr/sbin/enter-systemd-namespace systemctl enable --now cockpit.socket

Open a Web Browser

Open a web browser and navigate to http://localhost:9090. You might need to replace localhost with your WSL2 instance’s IP address if accessing it from another machine.

Log In

Log in using your system’s username and password.

go to this link:

follow as much as possible

This should install the entire system with Pytorch GPU accelerated

Leave a Reply

Your email address will not be published. Required fields are marked *