Creating Virtual Environments in Python

Dennis Appiah
2 min readAug 5, 2022

This article will expatiate the importance of creating a virtual environment inside every software project, and how it is done in python.

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python environments for them. For example, If application A needs version 1.0 of a particular module, however, application B needs version 2.0, then the requirements conflict, and installing either version 1.0 or 2.0 will leave one application unable to run.

Advantages of Virtual Environments

⦁ You can use different versions of Python for every project

⦁ You don’t clash packages; It provides a clean environment with unnecessary packages installed in our project directory.

Creating Virtual Environments (Windows, Unix, or macOS)

To create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path.

Activating Virtual Environments

Once you’ve created a virtual environment, you may activate it

On Windows, run

On Unix or macOS, run

Now, that you have successfully activated your virtual environment, you can install unique packages and dependencies for every project using the pip module.

I hope you enjoyed this article. Thanks for your time.

Feel free to connect with me: LinkedIn Twitter

--

--