The following document will guide you through to install WSL, Ubuntu distro, python,pyenv and poetry
If you are using Linux based system skip these steps for installing wsl & Ubuntu
-
First you need to Make sure your Windows version is at least Windows 10, version 2004. You can check your Windows version by going to Settings > System > About.
-
Open PowerShell as an administrator and run the following command to enable the WSL feature:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
-
Restart your computer when prompted.
-
You can now install everything you need to run WSL with a single command. Open PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting
Run as administrator
wsl --install
-
Then restart your computer.
-
To install Ubuntu-20.04 use the following command in powershell or command prompt then restart
wsl --install Ubuntu-20.04
- If you want to install additional distributions from inside a Linux/Bash command line (rather than from PowerShell or Command Prompt), you must use .exe in the command:
wsl.exe --install -d <Distribution Name>
- You can list your installed Linux distributions and check the version of WSL each is set to by entering the command in PowerShell or Windows Command Prompt:
wsl -l -v
- To set the default version WSL 2 when a new Linux distribution is installed, use the command:
wsl --set-default-version 2
- To set the default Linux distribution used with the wsl command, enter:
wsl -s <DistributionName>
or
wsl --setdefault <DistributionName>
replacing <DistributionName>
with the name of the Linux distribution you would like to use.
To install Python 3 in WSL Ubuntu, follow these steps:
-
Open the terminal in WSL Ubuntu.
-
To update the package list run the following command
sudo apt-get update
- To install Python 3 run the command
sudo apt-get install python3
- Verify the installation by running the command and it should display the version of Python 3 that you have installed.
python3 --version
- If you want to install pip for Python 3, run the command
sudo apt-get install python3-pip
- Verify the installation by running the command and it should display the version of pip that you have installed.
pip3 --version
- You now have Python 3 and pip installed in WSL Ubuntu. You can now use Python 3 to write and run your programs.
-
Open the terminal in WSL Ubuntu.
-
To update the package list Run the command
sudo apt-get update
- To install the necessary dependencies for pyenv run the command
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
- to install pyenv run the command
curl https://pyenv.run | bash
- Add the following lines to your
.bashrc
file:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
- To apply the changes run the command
source ~/.bashrc
- To install Python 3.10.0 run the command
pyenv install 3.10.0
- To set Python 3.10.0 as the global version run the command
pyenv global 3.10.0
- To set Python 3.10.0 as the local version run the command
pyenv local 3.10.0
- Verify the installation by running the following command it should display
Python 3.10.0
python --version
-
Open the Windows Terminal or the command prompt and type
wsl
to enter the Windows Subsystem for Linux. -
Once in the Linux environment, update the package list by typing
sudo apt-get update
and enter your password if prompted. -
Install poetry by running the following command
sudo apt-get install poetry
-
Wait for the installation to complete and then type
poetry
to confirm that it is installed correctly. -
If you see the poetry usage instructions, it means the installation is successful. You can now use poetry to create and manage your Python projects.