banner



How To Create Virtual Environment In Windows 10

Introduction

Earlier, I wrote an article on how to fix a Virtual Surround for Python development on Ubuntu. This article, as the title suggests, focuses on setting upwardly a virtual environment on Windows. I'm using Windows viii, and everything nosotros volition do here should work on other versions of Windows as well.

Installing and Running Python

Installing Python, or any other software, for that matter, is adequately like shooting fish in a barrel on Windows. You can download the Python installer from the Download Python page of the official website. The versions I will be using for this article, are iii.vi and 3.vii. Please experience free to choice your ain versions.

While installing Python three.half dozen, please make sure that you take selected the checkbox for "Add Python 3.6 to PATH". Also, note that I'k installing Python in "C:\Python\Python36" directory, which would be useful subsequently. So, I would recommend you to exercise the same, even so, you are not jump to.

Once washed, open up your PowerShell, type "python" and striking enter/return. You should see an output like to mine. You tin can exit Python past using the quit() or go out() call.

It'southward time to install Python 3.7 in the "C:\Python\Python37" directory. Please ensure that you lot select the checkbox for "Add Python 3.7 to PATH". Once done, close the current PowerShell, and open information technology again. Then type "python --version" and striking enter/return. You should see an output like to this one:

Notice how "python --version" returns the version to be "Python 3.7.0" and not "Python 3.half-dozen.6". The reason for this is the value of the PATH environment variable. To run across the value you lot need to,

  • right-click Calculator and select Properties
  • select Accelerate System Settings
  • from the pop-upwardly box select Avant-garde tab
  • select Environment Variables
  • select PATH so Edit

You lot tin now copy the value in your favorite text editor and look at it. Mine looks like the following.

  1. C:\Python\Python37\Scripts\;C:\Python\Python37\;C:\Python\Python36\Scripts\;C:\Python\Python36\;

When we execute the command "python" or "python --version", it looks into the "PATH" variable and finds Python iii.7 equally the first friction match, it stops there and looks no further. Therefore, if we desire to run "Python 3.half-dozen", we take to manually change the "PATH" variable or change the installation order which volition, in plough, change the variable.

Withal, there is a way to run a specified version of Python, and we can practise so by using the command "py -<python version>". Please refer to the image below.

Setting Virtual Environment

To set up a virtual environment, nosotros first need to install the package virtualenv using pip. To do so, open up your PowerShell and execute the following commands.

  1. python -1000 pip install --upgrade pip
  2. pip install virtualenv

If your requirement falls nether whatsoever of the following categories,

  • have merely one Python version installed
  • don't want to specify any Python version
  • desire to use default Python version (bank check your version past running "python --version" on the command line)

And so, you can simply create your virtual surround using the "virtualenv venv" command, where "venv" is the environment name. However, if none of the above categories satisfies your requirement, then follow along every bit information technology's time to create your virtual environment using with Python 3.6.

  1. cd .\Desktop
  2. mkdir project-36
  3. cd .\project-36
  4. virtualenv venv -p C:\Python\Python36\python.exe

Notice the last control. With the attribute "-p" we accept specified the Python version that nosotros want our virtual environment to use. In our case, it's Python 3.6, which we had installed at "C:\Python\Python36". If you installed it at a different location, please laissez passer the complete path here.

If you lot want to use Python 3.7 instead, all you need is to change the installation path for Python in the last command. Merely put in the path where you installed Python 3.vii and you are good.

Now, information technology's time to actuate the environment, check the Python version and likewise list the default packages installed for united states. To practise so, execute the post-obit commands and you should encounter a similar output as shown in the image that follows. The (venv) on the left shows that our virtual surround is agile.

  1. .\venv\Scripts\activate
  2. python --version
  3. pip list
  4. deactivate

Congratulations! Yous have successfully created your outset virtual environment for Python. And, y'all are now all prepare to outset your journey with Python evolution over Windows.

Summary

In this article, we successfully -

  • installed Python (different versions)
  • learned how to run specific Python version over control line
  • created virtual environments, running different versions of Python, using virtualenv package

If you are interested to learn more and gear up your Python virtual environment on Ubuntu (or other Linux based system), do check out my previous article where I walk you through each step in detail.

Source: https://www.c-sharpcorner.com/article/steps-to-set-up-a-virtual-environment-for-python-development/

Posted by: lloydevizint2002.blogspot.com

0 Response to "How To Create Virtual Environment In Windows 10"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel