How to create virtual environment in Python (venv and virtualenv)

Code With Khaled
2 min readDec 28, 2023

--

In the following article, we’ll look at virtual environments in Python using two prominent tools: venv and virtualenv. Virtual environments are vital to Python developers considering they offer a clean and segregated environment for their projects, preventing dependency conflicts and ensuring the project’s installation of packages.

By setting up a virtual environment in Python, you may create an exclusive area where you can install Python packages and dependencies unique to your project without interfering with other projects or the system-level Python installation.

To create virtual environment

1. Creating a Virtual Environment using venv

The actions to construct a virtual environment with venv in Python are as follows:

  1. On your computer, launch the terminal or command prompt. Go to the directory where the virtual environment is to be created. To switch directories, use the cd command. For instance, if your directory name is “pythonenv,” then type cd pythonenv or not, then create a new directory and press Enter to establish the virtual environment in the pythonenv directory.
  2. If you want to build a virtual environment with the name “env” use the following command on your terminal after you have entered the relevant directory: python -m venv env . Keep in mind that “env” is only one possible name for your virtual environment; you may select whatever name you choose. Hit Enter, then watch as the virtual world is constructed. It can take a few seconds.

Read More….

--

--

No responses yet