usage of virtualenv in Python

homepage-banner

As a Python developer, you may have faced the challenge of managing dependencies and ensuring that your code runs smoothly across different machines. The solution to this issue is the use of virtual environments, a tool that allows you to create isolated Python installations and manage your dependencies cleanly. In this blog post, we will explore the power of virtual environments and how they can help you streamline your development process.

Setting up and using virtual environments is relatively simple. You can create a virtual environment using the built-in venv module in Python 3 or use third-party tools like virtualenv or conda. Once you have created a virtual environment, you can activate it using a simple command, and you are ready to go.

## install virtualenv
pip install virtualenv

## create new python env
cd my_project_folder
virtualenv my_project

## activate and deactivate
source my_project/bin/activate
deactivate

## pip install user defined modules
pip install requests
pip freeze > requirements.txt
pip install -r requirements.txt

## cleanup
rm -rf my_project
Feedback







Disclaimer
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • Made with Material for MkDocs and improve writing by generative AI tools
  • Copyright issue feedback me#imzye.com, replace # with @