How to Set Up a Python Virtual Environment in Windows 10?

Estimated read time 2 min read

Setting up a Python virtual environment on Windows 10 is similar to setting up a virtual environment on other operating systems. Here are the steps to follow:

  1. Open Command Prompt by typing “cmd” in the search bar and selecting the Command Prompt app.
  2. Install the virtual environment package by typing the following command: pip install virtualenv
  3. Navigate to the directory where you want to create your virtual environment using the cd command. For example, to navigate to your Documents folder, you can type: cd Documents
  4. Create a new virtual environment by typing the following command: virtualenv env (replace “env” with the name you want to give to your virtual environment).
  5. Activate the virtual environment by typing the following command: .\env\Scripts\activate
  6. You should now see the name of your virtual environment in the command prompt, indicating that you are now working inside the virtual environment.
  7. You can now install any Python packages or libraries that you need for your project using pip, and they will be installed only in the virtual environment, keeping your system’s Python installation clean.
  8. To deactivate the virtual environment, simply type deactivate in the command prompt.

Here is an example of how you might set up a virtual environment and install some packages:

C:\> pip install virtualenv
C:\> cd Documents
C:\Documents> virtualenv venv
C:\Documents> .\venv\Scripts\activate
(venv) C:\Documents> pip install numpy
(venv) C:\Documents> pip install pandas

In this example, we are creating a new virtual environment called venv, activating it, and then installing the numpy and pandas packages using pip. When we are done working in the virtual environment, we simply type deactivate to exit the virtual environment.

Note that this is just a basic example to get you started. You can use virtual environments to isolate Python dependencies for any project, regardless of its size or complexity.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply