🐍
Python For Starters
  • Overview
  • Python for starters
  • Content
  • Foreword
  • Introduction To Python
    • Python Installation
    • Variables
    • Python Data Types
    • Python Data Structures
    • Python numbers
    • Python strings
    • Python Boolean
    • Python constants
    • Python Comments
    • Type Conversion
    • Control flow in python
  • Python Functions
    • Function Definition
    • Function Parameter
    • Recursive Functions
    • Using Global Variables in Functions
    • Lambda Functions
  • What are Data Structures
    • Python Lists
    • Python Tuples
    • Python Dictionaries
    • Python Sets
    • Iterable in python
    • Python Map, Filter & Reduce Functions
  • Error handling in Python
  • Loop ... Else Clause, Partial Functions & Type Hints
    • Partial Functions
    • Type Hints
  • Python Modules
  • Python Libraries & Packages
    • Python Packages
  • Directory & IO
    • Python IO Module
  • Pyenv
  • Virtual Environments
    • Pipenv
    • Virtualenv
  • Object Oriented Programming in Python
    • Class
    • Class Methods
    • Python Class Inheritance
    • Python Class Polymorphism
    • Python special methods
  • Appendix
  • Contributing
Powered by GitBook
On this page
  1. Virtual Environments

Virtualenv

virtualenv is a tool used to isolate specific Python environments on a single machine, allowing you to work with multiple versions of Python packages and libraries without conflicts. This can be useful if you need to work on multiple projects that require different versions of packages, or if you want to test your code on multiple versions of Python.

Here's how you can use virtualenv:

  • Install virtualenv:

pip install virtualenv
  • Create a new virtual environment:

virtualenv myenv

This will create a new directory called "myenv" that contains a copy of the Python interpreter and libraries, as well as a script called activate that you can use to activate the environment.

  • Activate the virtual environment:

source myenv/bin/activate

This will modify your shell prompt to indicate that you are now working in the virtual environment. Your virtual environment will also be the default Python interpreter until you deactivate it.

  • Install packages: With the virtual environment active, you can now install packages using pip as you normally would. These packages will be installed in the virtual environment, rather than globally on your system.

pip install <package-name>
  • Deactivate the virtual environment: When you are finished working in the virtual environment, you can deactivate it by running the following command:

deactivate

This will restore the original Python interpreter and libraries, and remove the virtual environment from your shell prompt.

PreviousPipenvNextObject Oriented Programming in Python

Last updated 2 years ago