Running Your Project Using Windows Subsystem For Linux (WSL)
Running Your Project Using Windows Subsystem For Linux (WSL)
Please be aware that setting this up can take an hour or longer. So, follow
all the steps carefully to prevent surprises!
Install WSL
Open Powershell and run:
wsl --install
This will download Ubuntu Linux (the most popular Linux distribution) by
default and will take a few minutes. If nothing happens, you need to explicitly
specify Ubuntu:
Once the installation is complete, you’ll see a new terminal window running
Linux. The rst time, you’ll need to setup an account to log into Linux.
Once you set up your account, you’ll see Linux command prompt indicated by a $
You can run pwd to print the current working directory. Note that Linux has a
different le system and path than Windows.
fi
This extension adds a few commands to VSCode. Open the Command Palette and
type Remote-WSL. Alternatively, you can click on the green remote indicator in
the lower left corner of the status bar
This will re-open our project folder in WSL. The rst time, it may take a few
seconds until the required components are downloaded.
The green remote indicator on the status bar will then show that your project is
running on WSL: Ubuntu
Open a terminal window in VSCode. You’ll see the command prompt has changed
from Windows to Linux style (starting with $).
fi
Sudo allows us to elevate the current user to have root (admin) privileges. This is
required for running certain commands like updating the package list. Using &&, we
can chain two commands.
After a couple of minutes, you’ll be told how much more space will be required to
upgrade these libraries. After that, allow 15-20 minutes for the update to complete.
Depending on your connection speed, updating may complete in less or more time.
python3 --version
Here, rst we tell Linux where it can nd the Python 3.9 package (by adding the
repository) so we can install it using APT.
python3.9 --version
If you run “python3 —version” again, you’ll still see version 3.8. That’s because the
python3 command is linked to python3.8 binary. To change the link, we need to
remove it and add it again:
sudo rm /usr/bin/python3
python3 --version
pip --version
pipenv --version
fi
Install MySQL
Our Django project uses mysqlclient to talk to MySQL. In order to install this with
pip later, rst we need to install a couple of packages in our Linux environment or
the installation of mysqlclient will fail.
We could install both these packages in one go but I deliberately split the command
into two so you ensure each package is successfully installed. To verify, run
You shouldn’t see any errors. If you do, stop and troubleshoot. Remember, Google is
your best friend!
mysql --version
By default, the root user doesn’t have a password. So press Enter when asked for
the password.
Create a database called storefront3. Note the ; at the end of the command. If you
forget that, the prompt will break into a new line where you can enter a ; to
terminate the command.
Next, set the password for the root user. Note that both root and localhost are
surrounded by single quotes.
Here, we set the password of the root user to P@ssword. Open settings.py, and set
the same password in the DATABASES setting.
pipenv install
pipenv shell
Now, your application is running on WSL. Next time you open VSCode, your
application will continue to run on WSL.
Remember, every time you open a terminal Window, you need to activate the virtual
environment:
pipenv shell