How To Setup A Python Virtual Environment On Windows 10

Reading Time: 4 minutes

A Virtual Environment or a “venv” is a Python module that creates a unique environment for each task or project. It installs the packages we need that are unique to that setting while keeping your projects neatly organized. Additionally, venv never actually modifies the system’s default Python versions or modules that are installed on the system. Using venv essentially allows for a unique working environment while avoiding any disruptions to other variants of Python that are used, but not related to our project.

Prerequisites

We recommend enabling the Windows Subsystem for Linux (WSL) in order to take full advantage of all the functionality of venv on Windows 10. This allows you to run a full Linux distribution within Windows to aid in the functionality of the new dev environment.

Why should I use WSL?

  • Many of the tutorials for Python are written for Linux environments. 
  • Most devs use Linux based packaging/installation tools.
  • Using WSL ensures compatibility between development and production environments

How do I enable WSL?

  • Go to Start > then search for “Turn Windows features on or off.”
  • Click the link to open the Windows control panel. 
  • Next, open the Windows features pop-up menu. 
  • Scroll down in that list to locate the “Windows Subsystem for Linux” option and select the checkbox.
  • Reboot.
Note:
WSL will require you to download a version of Linux noted here.If you’re using Windows (without WSL), simply install Python 3 from the Python website. The venv module is incorporated into that Windows installation.

Install Linux

There are multiple Linux distros that work with WSL. You can locate and install them from the Microsoft Store. We recommend starting off with a Ubuntu 18.04 LTS distribution as it’s up to date, has an excellent support community, and is well documented.

  • To install Ubuntu, click this Ubuntu 18.04 LTS link. This will open the Microsoft store where you can click on the Get button.
  • Once the download has completed, type “Ubuntu 18.04 LTS” into your Start menu.
  • Next, you’ll be asked to create a username and password as it will be your first time using this OS.
  • Subsequently, you will now be signed in automatically as the default user.
  • Lastly, we’ll need to run an update on the new OS. You can accomplish this by running:
sudo apt update && sudo apt upgrade

As a side note, Windows does not handle upgrades for this OS so you will need to ensure Ubuntu stays up to date by running the update and upgrade commands manually.

Note:
If for some reason the Microsoft store app is unavailable to you, you can manually download and install a Linux distribution by clicking on one of these links:

You can then install your distro using PowerShell. To install one of those distros, navigate to the folder which contains the newly downloaded Linux distributions. Once in that folder, run the following command in PowerShell (where app_name.aspx is the name of the distribution file):

Add-AppxPackage .\app_name.appx

Next, we’ll add the path to the distro into your Windows environment PATH using Powershell (eg. C:\Users\Admin\Ubuntu)

$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")

[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Admin\Ubuntu", "User")

Now, we can start the distro by typing in uubuntu.exe. Next, we should initialize the new instance.

Launch a distro

To finish the initialization of your newly installed distro, we will need to launch a new instance. You can accomplish this by clicking on the “launch” button in the Microsoft app store, or by launching the distro’s .exe file from the Start menu. Additionally, if using a Windows Server, you can start the distro’s launcher’s executable file (Ubuntu.exe) from the distro’s installation folder.

During the last stage of the installation, the distro’s files will be decompressed and stored locally on your PC. This process may take a few minutes but is only required once. Later initializations should take less than a second.

Setup

There are four basic steps to install a virtual environment on windows:

  1. Install Python
  2. Install Pip
  3. Install VirtualEnv
  4. Install VirtualEnvWrapper-win
Note:
Remember, these commands should be run within the WSL Ubuntu environment. Additionally, the sudo command may be needed if not running as the root user.

Step 1. Install Python 

Python 3.8.0 is the latest major release of Python.

  • Note: There is now a “web-based” installer for Windows. This installer will download the required software during the installation.
  • There are also Python redistributable files that contain the Windows builds, which makes it easier to include Python in another software bundle. 
  • If you installed Ubuntu 18.04 from the above list, Python3 comes pre-installed.
which python

Step 2. Install PIP

We suggest following the directions located here in our knowledge base. Python3 usually comes with pip preinstalled, however, if you get the error “pip command not found,” simply use the following method to install pip. 

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  • Download get-pip.py, and make sure you’re saving the file to your Desktop. 
  • At your Windows Command Prompt, navigate to your Desktop and run the get-pip.py script. After that, pip should work system-wide 
python3 get-pip.py
Note:
You may need to have administrative privileges at the command prompt to accomplish this task. For more info on this, follow the directions from Start a Command Prompt as an Administrator from the Microsoft TechNet website.
cd Desktop
Python get-pip.py

Step 3. Install Virtualenv 

In your Windows command shell prompt type in:

pip install virtualenv

Start virtualenv 

In your windows command prompt, head to your project location: 

cd my_project

 Once inside the project folder run: 

virtualenv env

Activate virtualenv 

On Windows, virtualenv (venv) creates a batch file called 

\env\Scripts\activate.bat

To activate virtualenv on Windows, and activate the script is in the Scripts folder :

\pathto\env\Scripts\activate

Example: 

C:\Users\'Username'\venv\Scripts\activate.bat

Step 4. Install VirtualEnvWrapper-win

 There are two main methods we recommend to install this batch script.

  • Using pip

pip install virtualenvwrapper-win
  • Install from source
git clone git://github.com/davidmarble/virtualenvwrapper-win.git

We then cd to the virtualenvwrapper-win folder and run: 

python setup.py install  

And that’s it! Python’s venv is set up and ready to use. 

Grab Your FREE Coupon Today!

Check out all the specials we have going on right now where you can save HUGE on our Dedicated, Cloud Dedicated as well as our VPS Servers! Additionally, check out the coupon below for even greater savings!!!

How To Create A Software Install List

Reading Time: 3 minutes

Purpose

The purpose of this article is to describe and explore ways to copy or backup your currently existing installed software titles into a single file for later use. We can then use this file to reinstall the software onto another system or clone the existing software across multiple Linux systems on or across a network. This method also prevents the need to install software titles one by one.

Continue reading “How To Create A Software Install List”

How to Use PyPI & PIP

Reading Time: 3 minutes
pypi logo

In this article, we will discuss how to access and utilize the Python Package Index or PyPI via the pip command.

PyPI is the default software repository for Python developers to store created Python programming language software developers and programmers alike use to publicize and share their software.

Continue reading “How to Use PyPI & PIP”

How to Install Scikit-Learn on Ubuntu 18.04

Reading Time: 5 minutes

In this tutorial, we are going to walk through how to install scikit-learn on an Ubuntu 18.04 server. We are going to walk through the installation both in a virtual environment with the Python package manager, Pip, and via Anaconda.

Continue reading “How to Install Scikit-Learn on Ubuntu 18.04”

How to Setup a Python Virtual Environment on Ubuntu 18.04

Reading Time: 3 minutes

In this article, we learn how to set up a python virtual environment on Ubuntu 18.04. Python is a high-level dynamic programming language. Its straightforward syntax makes it a great choice for fast development. Python is used by system administrators to automate workloads and by developers for application development as well.

Continue reading “How to Setup a Python Virtual Environment on Ubuntu 18.04”

How to Install PIP on Ubuntu 18.04

Reading Time: 3 minutes

What is PIP?

In this article, we will discuss how to install PIP on Ubuntu 18.04. PIP is a tool used to install and manage Python packages. This tutorial will show how to install and check the version of PIP as well as run a few basic commands for using PIP on Ubuntu 18.04.

Continue reading “How to Install PIP on Ubuntu 18.04”

How to Install Microsoft SQL on Linux

Reading Time: 6 minutes

In this article, we will be discussing how to install Microsoft SQL or MSSQL on Linux. Microsoft SQL, colloquially referred to as MSSQL, is a relational database management system created by Microsoft. Open-source MySQL and PostgreSQL are typically synonymous with Linux distributions, but working with MSSQL on Linux is also supported. MSSQL offers some features that its open-source counterparts don’t, and depending on application requirements, it might be the right choice for an RDBMS. In this tutorial, we are going to walk through how to install MSSQL on CentOS 7 and Ubuntu 16.04.

Continue reading “How to Install Microsoft SQL on Linux”

How To Install Software From Source on Ubuntu

Reading Time: 6 minutes

In this article, we are going to cover the available options for installing software on Ubuntu. By the end of this article, you’ll be equipped with an arsenal of tools for installing the exact software you want on your Ubuntu server! We will be installing three different software packages from source, deb, and flatpack.

Typically, the Ubuntu OS ships with an excellent package management system called APT. Apt-get, or the more recent apt command, are the interfaces users would typically utilize to search for, download, and install packages.

What happens when you need to install something on your Ubuntu server, but the software package isn’t available for installing via apt?

What if you need to build a software package from source to access the newest features from the latest version of that package?

How do I locate the dependencies for the software I need?

We will answer those questions below!

Continue reading “How To Install Software From Source on Ubuntu”

How To Install TensorFlow on Ubuntu 18.04

Reading Time: 2 minutes

In this tutorial, we are going to set up TensorFlow in a virtual Python environment on Ubuntu 18.04. TensorFlow is an open-source framework, developed by the Google Brain team, designed to be a high-level interface for implementing machine learning and mathematical operations. This library provides developers an avenue to work on complex projects like neural networks through an easy to use Python API. One of the significant benefits of having a Python front-end is that it is portable between operating systems like Linux and Windows.

Continue reading “How To Install TensorFlow on Ubuntu 18.04”

How to Install Node Version Manager on Ubuntu

Reading Time: 2 minutes

The Node Version Manager (NVM) is a command-line utility used to manage and switch between multiple active versions of Node.js on a single system. Whether you’re an admin or a developer, being able to change the javascript runtime environment on your system simplifies testing applications across different versions.

Continue reading “How to Install Node Version Manager on Ubuntu”