DEV Community

Subhash Bohra
Subhash Bohra

Posted on

Learn Python with AWS - Day 2

Virtual Environments

Today we will learn about virtual environments. A virtual environment in python is a container in which all your code and other python packages reside. It allows you to keep your python configuration separate from other versions on your system. It is a good idea to always use a virtual environment when developing python code.

To create a virtual environment we will use the command:



python -m venv my_venv



Enter fullscreen mode Exit fullscreen mode

Once the virtual environment has been created, you need to activate it. Once activated, your code runs inside the environment, including any packages you install. To activate the environment use one of the following commands:

Linus/mac OS:



source my_venv/bin/activate



Enter fullscreen mode Exit fullscreen mode

Windows (Git-Bash):



source my_venv/Scripts/activate


Enter fullscreen mode Exit fullscreen mode

To know you are inside the virtual environment your command prompt will have the prefix (my_venv). Now any packages you use will be stored in a folder structure inside your virtual environment.

To exit from the virtual environment, you type deactivate and the command prompt will no longer be prefixed by (my_venv).

Python Environment

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay