Skip to main content

Command Palette

Search for a command to run...

Creating And Activating Virtual Environments in Python

Published
•2 min read•View as Markdown
Creating And Activating Virtual Environments in Python
N

👉 I'm an ML Research 7 Open-Source Dev Intern at Menlo Park Lab. 👉 I'm a Machine Learning and MLOps Enthusiast. 👉 I’m One Of The Semi-Finalist Of The Biggest ICT Olympiad In Bangladesh Called “ICT Olympiad Bangladesh” In 2022. 👉 I've More Than 15 Google Cloud Badges. ⭐️ Wanna Know More About Me? Drop Me An Email At: naymul504@gmail.com ★

Introduction👇


A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. Imagine a scenario where you are working on two web-based Python projects one of them uses Django 4.0 and the other uses Django 4.1 (check for the latest Django versions and so on). In such situations, we need to create a virtual environment in Python that can be really useful to maintain the dependencies of both projects.


How to create a virtual environment👇


There are many ways to create a virtual environment in Python. But we will be doing the easiest one not to waste more time on it and work on our own things.

Let's get into creating a virtual environment for your Python projects:

For that first of all we need to install a Python library on our machine named 'virtualenv':

Run the following command to install the virtualenv library:

pip install virtualenv

The next task is to create a virtual environment using that library

Use the following command to create a virtual environment:

virtualenv -p python 'your enviroment name like venv, virtualenv anything you like'

The next task is to activate the virtual environment in your machine, for that run the following command according to your system

For Gnu-based Linux users like Ubuntu/Kali Linux/Debian etc. or WSL users on windows

source ./venv/Scripts/activate

For Windows users(Powershall):

./venv/Scripts/activate.ps1

For Mac users:

source ./venv/bin/activate

Congrats🎉, You have created a virtual environment and activated that!!!

Now you can install all the dependencies that you need for your project.


Before we end…

Thank you for taking the time to read my posts and share your thoughts. If you like my blog please give it a like, comment, and share it with your circle and follow for more I look forward to continuing this journey with you.

Let’s connect and grow together. I look forward to getting to know you better😉.

Here are my social links below-

Linkedin: https://www.linkedin.com/in/ai-naymul/

Twitter: https://twitter.com/ai_naymul

Github: https://github.com/ai-naymul

More from this blog

A

All About AI

13 posts

I am an ML Research & Open-Source Dev Intern at Menlo Park Lab. I also love to do open-source. And Sharing my knowledge and my journey of becoming a MLOps Engineer.