Python Virtual Environments in Windows (2024)

What is a Python Virtual Environment?

A Python virtual environment is an isolated Python environment that allows you to maintain separate dependencies for different Python projects. Setting up a Python virtual environments for each project ensures that it will have the requirements it needs without interference from other projects.

Why use a Python Virtual Environment?

When using Python, you might need to install packages and modules that aren't a part of the standard library. While doing a 'pip install –user some_package' will allow you to install Python packages in your home directory, you may run into issues later on with package dependencies. For example, if you are working on two different projects and Project 1 requires version 1.0 of a library whereas Project 2 requires version 2.0 of that same library, installing the dependency for Project 2 will likely break Project 1. An easy way around this is to create a separate virtual environment for each of your projects. The virtual environments are isolated from each other, allowing you to install dependencies for one project without worrying about breaking something in the other project.

Starting up the Anaconda prompt

Connect to the CLA WTS servers and select Start → All Programs → Anaconda$version→ Anaconda Prompt (where $version denotes the Anaconda Python version you want to use). This will open up a command window that is configured to use Python, conda, and other tools.

Creating a Python Virtual Environment

In the Anaconda Prompt window, you will notice that the prompt is preceded with (base). This indicates that you are in the default environment named "base." You don't want to install programs into the base environment. Instead, you will want to use the 'conda' command to create your own virtual environment to keep your projects isolated from each other. In this example, we will create a Python 3.6 virtual environment named 'Project1'.

conda create -n Project1 python=3.6

Using the Virtual Environment

To use the virtual environment, use the conda command to activate it.

conda activate Project1

After activating the virtual environment, the command prompt will be preceded by '(Project1)' instead of '(base)' to indicate that you are now in the Project1 virtual environment. Once you have activated the environment, you can install packages and run any Python scripts associated with the project.

Deactivating the Virtual Environment

When you are done working in your virtual environment, you will want to deactivate it using the 'deactivate' command. Your prompt will return to normal, indicating your virtual environment is no longer active and your PATH and shell variables have been returned to normal.

conda deactivate

Putting it all Together

conda create -n Project1 python=3.6
conda activate Project1
conda deactivate
conda create -n Project2 python=3.6
conda activate Project2
conda deactivate

Listing your Virtual Environments

To see a list of the Python virtual environments that you have created, you can use the 'conda env list' command. This command will give you the names as well as the filesystem paths for the location of your virtual environments.

conda env list

Note that in the list of environments, one of the environments will have an asterisk (*) by it. This is used to denote the environment that is currently active.

Listing Packages Installed in a Virtual Environment

After activating a virtual environment, if you want to see what packages are installed, you can use the 'conda list' command list the packages as well as their versions.

conda activate Project1
conda list

Installing Packages to a Virtual Environment

Virtual environments are created with a barebones site library when not linked to the base Anaconda installation. Unless your code only relies upon the Python standard library, you will want to use either the conda or pip package managers to install additional libraries.

Differences between conda and pip

The differences between conda and pip are often misunderstood as both package managers provide similar functionality. On one hand, pip is well-adopted in the Python community and the Python Package Index (PyPI) contains a vast array of packages maintained by the community. On the other hand, Conda is a general-purpose package manager, can help track dependencies for non-Python libraries, and is fully compatible with pip. In general, each package manager compliments the other and you are free to use whichever provides the package you wish to install.

Common Commands

FunctionCondaPip

Search for a package in the default repo

conda search {package}

pip search {package}

Install a package

conda install {package}

pip install {package}

List installed packages

conda list

pip list

Upgrade a package

conda upgrade {package}

pip install --upgrade {package}

Remove a package

conda remove {package}

pip uninstall {package}

Deleting a Virtual Environment

When you are done with a project and have no further need for the associated Python virtual environment, you can delete it with the 'conda remove' command.

conda remove -n Project1 –all

Note: if you get an error that states “cannot remove current environment. deactivate and run conda remove again”, make sure that you have deactivated the environment. If the environment has been deactivated and you still get the same error, use the 'p' switch to the 'conda remove' command to specify the path to the virtual environment. (You can get the paths for all of your virtual environments with the 'conda env list' command.)

conda remove -p /path/to/virtual/env --all
Python Virtual Environments in Windows (2024)
Top Articles
Les conseils du Revenu pour gagner avec l’immobilier - Le Revenu
How to Get a 500K Job in Tech — Finding the Right Company | | Interview Kickstart
jazmen00 x & jazmen00 mega| Discover
Kevin Cox Picks
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Alan Miller Jewelers Oregon Ohio
Craigslist Benton Harbor Michigan
Find All Subdomains
Dee Dee Blanchard Crime Scene Photos
Roblox Character Added
The Many Faces of the Craigslist Killer
Day Octopus | Hawaii Marine Life
fltimes.com | Finger Lakes Times
Nonne's Italian Restaurant And Sports Bar Port Orange Photos
Labor Gigs On Craigslist
Cyndaquil Gen 4 Learnset
1v1.LOL - Play Free Online | Spatial
Amazing deals for DKoldies on Goodshop!
Weepinbell Gen 3 Learnset
Adt Residential Sales Representative Salary
Joan M. Wallace - Baker Swan Funeral Home
Mj Nails Derby Ct
Rochester Ny Missed Connections
Rubber Ducks Akron Score
Best Sports Bars In Schaumburg Il
Craigslist Alo
How To Tighten Lug Nuts Properly (Torque Specs) | TireGrades
Divina Rapsing
Impact-Messung für bessere Ergebnisse « impact investing magazin
Unable to receive sms verification codes
Cowboy Pozisyon
30+ useful Dutch apps for new expats in the Netherlands
*!Good Night (2024) 𝙵ull𝙼ovie Downl𝚘ad Fr𝚎e 1080𝚙, 720𝚙, 480𝚙 H𝙳 HI𝙽DI Dub𝚋ed Fil𝙼yz𝚒lla Isaidub
Barbie Showtimes Near Lucas Cinemas Albertville
Elanco Rebates.com 2022
Metra Schedule Ravinia To Chicago
Craigslist Mexicali Cars And Trucks - By Owner
My Locker Ausd
Dcilottery Login
Lonely Wife Dating Club בקורות וחוות דעת משתמשים 2021
Conan Exiles Armor Flexibility Kit
Inducement Small Bribe
Jamesbonchai
Content Page
BCLJ July 19 2019 HTML Shawn Day Andrea Day Butler Pa Divorce
Go Nutrients Intestinal Edge Reviews
Learn4Good Job Posting
UNC Charlotte Admission Requirements
Makemkv Key April 2023
Gear Bicycle Sales Butler Pa
Craigslist Centre Alabama
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6220

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.