Notes

Python - Create virtual environment with venv and virtualenv

author: Paul Kim

categories: python

tags: python

Create virtual environment with venv on Mac/Linux (Python 3.3+)

# create virtual environment with venv (Python 3.3+)
python3 -m venv path-to-venv

# activate virtual environment
source path-to-venv/bin/activate

# freeze packages (venv)
pip freeze > requirements.txt

# install required packages
pip install -r requirements.txt

# deactivate virtual environment
deactivate

Create virtual environment with virtualenv on Mac/Linux (Python 2.6+ and Python 3.3+)

# create virtual environment with virtualenv (Python 3.3+)
python3 -m virtualenv path-to-venv
virtualenv path-to-venv

# create virtual environment with virtualenv (Python 2.6+)
python2 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
source path-to-venv/bin/activate

# freeze system and local packages (virtualenv)
pip freeze > requirements.txt

# freeze local packages (virtualenv)
pip freeze -l > requirements.txt

# install required packages
pip install -r requirements.txt

# deactivate virtual environment
deactivate

Create virtual environments with venv on Windows (Python 3.3+)

# create virtual environment with venv (Python 3.3+)
py -3 -m venv path-to-venv

# activate virtual environment
path-to-venv\Scripts\activate.bat

# freeze packages (venv)
py -3 -m pip freeze > requirements.txt

# install required packages
py -3 -m pip install -r requirements.txt

# deactivate virtual environment
deactivate

Create virtual environments with virtualenv on Windows (Python 2.6+ and Python 3.3+)

# create virtual environment with virtualenv (Python 3.3+)
py -3 -m virtualenv path-to-venv
virtualenv path-to-venv

# create virtual environment with virtualenv (Python 2.6+)
py -2 -m virtualenv path-to-venv
virtualenv path-to-venv

# activate virtual environment
path-to-venv\Scripts\activate.bat

# freeze system and local packages (virtualenv)
py -2 -m pip freeze > requirements.txt

# freeze local packages (virtualenv)
py -2 -m pip freeze -l > requirements.txt

# install required packages
py -2 -m pip install -r requirements.txt

# deactivate virtual environment
deactivate

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.