Python Virtual Environment

chanduthedev
2 min readSep 25, 2023

--

In this article we will learn about python virtual environment
- What is virtual environment in python?
- Why Virtual environment?
- What are the problems Virtual Environment will solve?
- How to create and use virtual environment in Mac

  • What is virtual environment?
    - Virtual Environment(VE) is creating a separate working environment (like Sand box)for a specific project with in the system
    - With VE, all the dependencies are installed within the VE are accessible to only this project and not accessible outside of the configured project
    - You can create as many VE’s as you want with in the system
  • Why Virtual Environment(VE)?
    -
    Now a days all projects required many dependency packages/modules. These dependencies are with different versions. how to track all these packages and its versions with in the system?
    - Some times we need to work on different projects simultaneously and each project may required of same dependency with different version. how to handle these scenarios?
    - How to install dependencies which are only specific to project and installed dependencies should not effect other projects?
  • What are the problems Virtual Environment will solve?
    - You can track what are the dependencies project is using and their versions
    - You can work multiple projects in the same system/machine without effecting any other project dependencies.
    - Same dependency with different version can be used in the same machine. E.g pandas 2.1 version can be used in one project and pandas2.0 version can be used in another project in the same machine.
  • How to create and use VE?
    - venv is the virtual environment python package we need to use
    - To create python virtual environment in mac, executing below command
>python3 -m venv any_name_you_want

- After creating a VE, Need to enable VE to use, by executing below command.

>source any_name_you_want/bin/activate

- You can disable if you are not using VE by executing below command

>deactive

--

--

No responses yet