My Development Environment Set up on Windows to use Python for Web Dev & Data Science
Tags: python, wsl, beginners, vscode
Published: 2020-02-24 08:24:06

*Originally published on my blogging site [ajeet.dev](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/)*


---

*This blog post is a step-by-step guide to install and use Python for web development, programming, data science or machine learning on a Windows machine using the Windows Subsystem for Linux and VS Code Editor. This post is written exclusively for the beginners in tech.*

---

**I have planned to write several blog posts on Python. All of them will be focused on the beginners to get them started with Python for Data Science. Please follow the updates here : [ Learn Python Step by Step - A Blog Series by Me 🚀](https://ajeet.dev/newbie-in-python/)**

---

*I am a newbie in tech. This blog post is based on my personal experience. Feedback Welcome. Would really appreciate your time 🙏*

---


Techies have different set-ups on a Windows machine to use Python for web development, machine learning or data science. For the newbies in tech, I recommend any one of the following two development environment set-ups (also recommended by Microsoft) to start their coding journey:

1.  **Use Windows Subsystem for Linux (WSL) and VS Code**:
     This is the approach we are going to follow in this blog post. We will 
    use a Microsoft tool - Windows Subsystem for Linux - to set up a Linux 
    distribution on a Windows machine. Newbies in tech who have been using a
     Windows desktop for years must read [this blog post explaining the benefits of using Windows Subsystem for Linux](https://ajeet.dev/switching-from-windows-to-linux/ "this blog post explaining the benefits of using Windows Subsystem for Linux"). In this set up, we will install and use Python inside the WSL, not directly on Windows. I am using this setup for two reasons: One, **Build web applications using Python** - Most of the resources and instructions for Python web development are written by and for the Linux users. The resources use Linux-based packaging and installation tools. Thus, the support is endless for the Linux users. Read[Why Linux Is Better For Programming & Web Dev](https://ajeet.dev/linux-vs-windows-os/ "Why Linux Is Better For Programming & Web Dev"). Second, **Learn data science and machine learning** - I can extend this set up to learn data science or machine learning. For example, I can install [Jupyter](https://jupyter.org/ "Jupyter") and natively edit Jupyter notebooks in VS Code inside the WSL. I can easily install 
    and use several Python's data science & machine learning libraries to do several tasks such as data cleaning, analysis, visualizations, and build machine learning models.
2.  **Use Windows 10 and VS Code**:
     You can use this set up to use Python for something other than web development. In this case, we install Python directly on Windows 10 using the Microsoft Store. This will help you learn Python using Windows, but not using the WSL tool. At any point of time, you can always install WSL to learn web development. Learn more about this setup [here](https://docs.microsoft.com/en-us//windows/python/beginners "here"). I don't use this setup to learn programming using Python. Read [my views](https://ajeet.dev/linux-vs-windows-os/ "Linux Vs Windows for programming") on why I chose a Linux environment to learn programming. 




### Table of Contents

-   [💻 Windows Subsystem for Linux, VS Code Editor, Python Extension = The Deadly Trio](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14ldknk9)
-   [✅ Install Windows Subsystem for Linux (WSL)](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14lf4ova)
-   [⚙️ Set up VS Code to work with WSL](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14lf4ova)
-   [🛠️ Install Python and its modules inside WSL](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14llg7dg)
-   [⬇️ Install Python Extension to work with VS Code](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14mc7c8h)
-   [🏃‍♂️ Run a Python program](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14pqq44m)
-   [💡 What's Next - Setup Jupyter Notebook with VS Code](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e16t7n223)
-   [🧰 Additional resources for continued learning](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/#mcetoc_1e14vfglu0)


### **💻 Windows Subsystem for Linux, VS Code Editor, Python Extension = The Deadly Trio**

Microsoft has been working really hard to develop various new-age tools for the developers and techies to bring web development, data science and machine learning to the masses. It created Azure cloud computing service and TypeScript open-source programming language. It acquired GitHub and R software. It developed source-code editor VS Code, Windows Subsystem for Linux (a tool to use Linux on windows without installing any virtual machine software), and has been continuously working to improve Microsoft Terminal. It clearly shows Microsoft tools have been slowly gaining the popularity among data scientists, engineers, and developers.

This combination of Windows Subsystem for Linux (WSL), VS Code editor and Python extension is truly a solid set up to work with Python for anything, be it data science, machine learning, artificial intelligence or web development.

We will install and use the three tools by Microsoft to learn Python on Windows 10. Let us start installing one by one.

### **✅ Install Windows Subsystem for Linux (WSL)**

I have already written a how-to-guide to set up WIndows Subsystem for Linux (WSL). [Follow this guide to set up WSL](https://ajeet.dev/windows-subsystem-for-linux/ "Follow this guide to use WSL") - a powerful tool built by the Microsoft. In this guide, you will learn how to install and use Linux inside a Windows machine without installing any Virtual Machine software. You don't have to leave your favorite Windows UI anymore. Additionally, use [this guide (optional) to create files and folders inside WSL](https://ajeet.dev/how-to-use-windows-subsystem-for-linux/ "this guide to create files and folders inside WSL").

### **⚙️ Set up VS Code to work with WSL**

For the beginners, I have written a comprehensive guide on how to work with VS Code editor inside the WSL. [Follow this step-by-step guide](https://ajeet.dev/developing-in-wsl-using-visual-studio-code/ "Follow this step-by-step guide"). In this guide, you will learn how to set up VS Code as our text editor / integrated development environment (IDE) to work with WSL. The cool thing is you can run all the Linux commands, such as `mkdir` to create a project directory and `touch` to create a file, using VS Code integrated terminal.

![RUn Linux commands in VS Code integrated terminal](https://dev-to-uploads.s3.amazonaws.com/i/z6irzccqfw8m980yw1ni.png)


So, you don't have to leave you favorite Code Editor too.

### **🛠️ Install Python and its modules inside WSL**

If you have followed my [WSL guide](https://ajeet.dev/windows-subsystem-for-linux/ "WSL guide"), you would have seen Ubuntu terminal by now. Ubuntu 18.04 LTS comes with Python3 version installed. But it leaves out some of the modules and packages that Python applications often uses that don’t come as part of the standard library. We will install a couple of them.

Before installing them, one should make sure Python3 is already installed. To confirm, run `python --version` in the VS Code integrated terminal. You will see Python version (version 3.6.9 in my case). Make sure you have WSL installed on your Windows machine, and you have set up VS code server using the guides in the previous section. To update the Python version, first you should update your Ubuntu version using this command: `sudo apt update && sudo apt upgrade`. The terminal will ask you for the password you set up during installing the WSL tool. Type your password (the password will not be visible) and press Enter button using your keyboard. During this process, if the terminal asks you "*Do You want to continue? [Y/n]*", just press Y using your keyboard, and hit Enter button. It is basically seeking your permission to download something from the internet. Make sure you read first.

Now, run this command to update Python version: `sudo apt upgrade python3`

![Check Python Version](https://dev-to-uploads.s3.amazonaws.com/i/kn35rtvofnfbhr2oge5r.png)



Next, we will install **pip** - the standard package manager for Python. Run this command in the same VS Code integrated terminal:`sudo apt install python3-pip`. Pip is a package installer for Python that helps us install packages from the [Python Package Index](https://pypi.org "Python Package Index"). You can install Pandas - a Python package used for data analysis, time series, and statistics by running this command: `pip install pandas`. Note that depending on your environment, you might have to [use pip3 instead of pip](https://python-forum.io/Thread-What-s-the-difference-between-pip-and-pip3 "use pip3 instead of pip") in the above command.

Now, we will install **venv** - a module that provides support to create and manage lightweight virtual environments. Run this command in the terminal:`sudo apt install python3-venv`.

[Learn more about pip and venv](https://docs.python.org/3/tutorial/venv.html "Learn more about pip and venv").

### ⬇️ **Install Python Extension to work with VS Code**

Once you have installed the Python packages and modules inside Remote - WSL, you must install the VS Code Python extension inside WSL even if you have installed it locally (Windows machine). If you don't understand how extensions work locally and inside Remote - WSL, you must read this [short info on managing VS extensions](https://ajeet.dev/developing-in-wsl-using-visual-studio-code/#mcetoc_1e14vfglu0 "short info on managing VS extensions").

To install Python extension, press CNTRL+SHIFT+X button simultaneously using your keyboard. This will bring up the Extensions view in the Left/Right side of the Code Editor. In the top Search box, enter "Python". Look for "Python (ms-Python.Python)" by Microsoft extension. Click on Install or *Install in WSL:Ubutnu-18.04* button.

![Install Python Extension inside Remote WSL](https://dev-to-uploads.s3.amazonaws.com/i/y7rgbd9ckrms3gmsh5sz.png)


Once you have installed the extension, VS Code will ask you to reload the 
code editor. Click on Reload Required button, if asked. This will reload VS Code. The final view may look like this:

![Python installed in Remote WSL](https://dev-to-uploads.s3.amazonaws.com/i/je1ilkjsi0mh8yz0efg3.png)

 

Python is an interpreted language, which means we should tell our text editor, here VS Code, to select an interpreter in order to run Python code using VS Code editor. Python supports different types of interpreters (Python2, Anaconda, etc). We will use Python 3.6.9 though you can install different versions of Python and use them as interpreters for different projects. To choose a Python 3 interpreter, bring up the **Command Palette **view of the VS Code. Press Ctrl+Shift+P button simultaneously using your keyboard, type **Python: Select Interpreter**, and select it from the drop-down.

![How to select a python interpreter](https://dev-to-uploads.s3.amazonaws.com/i/r0xnvk6xcaxriq9a439e.png)

 

Once you click the Python interpreter, the drop-down will show you Python 
versions installed inside WSL. I can see only one as I have installed one only version of Python. Click on "Python 3.6.9 64-bit".

![Select Python Interpretor](https://dev-to-uploads.s3.amazonaws.com/i/r8z6j2b9vb7rz3w35q6t.png)



Microsoft will download the Python language server. Once the download finished, 
you would see the Python version you selected as an interpreter in the Bottom Status bar.

![VS Code UI View after Python Interpreter is selected](https://dev-to-uploads.s3.amazonaws.com/i/mkplevugn5ywbnmjy1er.png)
 

If you don't see the version you like to choose in the dropdown, follow this guide to [configure Python environments](https://code.visualstudio.com/docs/python/environments "configure Python environments"). 

Let us test our set up if it actually works. Open VS Code integrated terminal. If you don't know how integrated terminal works, please go through my blog post on [how to set up VS Code to work with WSL](https://ajeet.dev/developing-in-wsl-using-visual-studio-code/ "how to set up VS Code to work with WSL"). Enter the command: python3 . You will get the Python interpreter. Run the command: `print("I am Ajeet")`. You will see the statement "I am Ajeet".

![Test Python Interpreter](https://dev-to-uploads.s3.amazonaws.com/i/ba4qh2s8d2m3j4igq6bb.png)

 

Newbies should [try out some more simple codes](https://docs.microsoft.com/en-us//windows/python/beginners#hello-world-tutorial-for-some-python-basics "try out some more simple codes") in the Python interpreter. Stop the terminal by pressing Ctrl+Z button keyboard buttons in the terminal. You will see the text "Stopped ... Python3". To[clear/delete](https://askubuntu.com/questions/25077/how-to-really-clear-the-terminal "clear/delete") the commands you entered in the terminal, press  Ctrl+L button. This completes our Python set up process inside the Remote - WSL.

### 🏃‍♂️ **Run a Python program**

We just ran a simple code in Python interpreter. Let's create a simple Python program and run it using VS Code inside WSL. This will also make sure we have selected the correct Python interpreter. Follow these steps:

In the VS Code integrated terminal, enter command `ls` to see all the current project directories. Create a new project directory "ajeet_python" by entering this command: `mkdir hello_python` . Create a Python file inside this folder. Enter `touch ajeet_python/learn.py` . The .py means we are creating a Python file. Now go to the newly created folder. Enter `cd ajeet_python` . To see the newly created Python file, enter `ls` . You can also see both the file and folder in the left side bar of the VS Code UI (called VS Code File Explorer).

![Create a Python file inside WSL](https://dev-to-uploads.s3.amazonaws.com/i/y0v20s5fteh03k6a20b2.png)

 

Inside the newly create Python file learn.py, let us write a code and save it. Open the file by double clicking on it. Copy this statement `print("Hello to everyone")`paste it in the file, and save by pressing Ctrl+Z  button keyboard buttons. Now, we have to run the Python "Hello to everyone" program. In the integrated terminal, enter `python3 learn.py` . This will run your program you just created, and the Python interpreter will print "Hello to everyone" in the terminal window.

![Run your Python program](https://dev-to-uploads.s3.amazonaws.com/i/ovxxipuwy5wtshjoez0d.png)

 

Yay 🎉🎉 Congrats! We have set up our Python development environment on Windows machine.

### 💡 **What's Next - Setup Jupyter Notebook with VS Code**

I am going to write about setting up the Jupyter notebook with VS Code editor to learn data science and machine learning on Windows 10. Blog post coming tomorrow at my blogging website. Meanwhile, here is the Table of Contents.

![Blog on Setting up the Jupyter Notebook with VS Code](https://dev-to-uploads.s3.amazonaws.com/i/ma816pm73qx6c1giuyq4.png)

### 🧰 **Additional resources for continued learning**

I recommend the following resources to help you in continuing to learn Python on Windows using WSL and VS Code. Don't miss!

-   [ Learn Python Step by Step - A Blog Series by Me 🚀](https://ajeet.dev/newbie-in-python/)
-   [Create a virtual environment](https://docs.microsoft.com/en-us//windows/python/web-frameworks#create-a-virtual-environment "Create a virtual environment")
-   [Create a simple app using Flask - a Python web framework](https://docs.microsoft.com/en-us//windows/python/web-frameworks#hello-world-tutorial-for-flask "Create a simple app using Flask - a Python web framework")
-   [Create a simple app using Django - a Python web framework](https://docs.microsoft.com/en-us//windows/python/web-frameworks#hello-world-tutorial-for-django "Create a simple app using Django - a Python web framework")
-   [All the latest updates about Python at Microsoft](https://devblogs.microsoft.com/python/ "All the latest updates about Python at Microsoft")
-   [Developing with Python on Windows](https://docs.microsoft.com/en-us//windows/python/resources "Developing with Python on Windows")
-   [Microsoft Guides to learn Python](https://docs.microsoft.com/en-us//windows/python/ "Microsoft Guides to learn Python")

---

*Credits 🙏 : * 
*[Official Microsoft Docs on WSL](https://docs.microsoft.com/en-us//windows/python/web-frameworks "Official Microsoft Docs on WSL")*  
*Emojis taken from [Emojipedia](https://emojipedia.org/)*  
*Cover image built with [BlogCover](https://ajeet.dev/dev-environment-set-up-on-windows-to-learn-python/blogcover.now.sh/ "BlogCover")*


---

<a href="https://ajeet.dev/subscribe">![Subscribe to Ajeet.dev Newsletter](https://dev-to-uploads.s3.amazonaws.com/i/ma2y6t716f7u0l9gzr91.png)


---