0% found this document useful (0 votes)
21 views

Ilyes64 - Python Virtual Environments

A virtual environment is a tool that allows Python packages to be installed locally for a specific project in an isolated directory. The most popular virtual environment managers are virtualenv, venv, virtualenvwrapper, pipenv, and poetry. Virtualenv and venv are used to create and activate virtual environments on macOS, Linux, and Windows. Pipenv automates the creation of virtual environments and generates a Pipfile to track project dependencies. When installing a package for the first time with Pipenv, it will create a virtual environment and Pipfile.

Uploaded by

fraudianone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Ilyes64 - Python Virtual Environments

A virtual environment is a tool that allows Python packages to be installed locally for a specific project in an isolated directory. The most popular virtual environment managers are virtualenv, venv, virtualenvwrapper, pipenv, and poetry. Virtualenv and venv are used to create and activate virtual environments on macOS, Linux, and Windows. Pipenv automates the creation of virtual environments and generates a Pipfile to track project dependencies. When installing a package for the first time with Pipenv, it will create a virtual environment and Pipfile.

Uploaded by

fraudianone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Virtual Environments Cheat Sheet

by Ilyes KAANICH (ilyes64) via cheatography.com/124061/cs/23639/

What is a virtual enviro​nment?

A virtual enviro​nment is a Python tool for dependency management and project isolation. They allow Python site packages (third party libraries)
to be installed locally in an isolated directory for a particular project.

Most Popular Virtual Enviro​nment Manager

virtualenv The most popular and work with Python 2 and 3


venv A standard library, similar to virtualenv shipped with Python 3
virtualenvwrapper A set of extensions to virtua​lenv. Useful when using multiple virtualenv direct​ories.
pipenv Less popular, It automa​tically creates and manages a virtualenv for your projects by combining Pipfile, pip and virtualenv
into one command on the comman​d-line.
poetry Similar to pipenv
conda Included in all versions of Anaconda and Miniconda. Anaconda brings many of the tools used in data science and machine
learning with just one install.

Using virtualenv and venv

Installing virtualenv macOS and Linux python3 -m pip install --user virtualenv

Windows py -m pip install --user virtualenv

Creating a virtual enviro​nment macOS and Linux python3 -m virtualenv my-env

Windows py -m virtualenv my-env

Activating a virtual enviro​nment macOS and Linux source my-env​/bi​n/a​ctivate

Windows .\my-e​nv​\Scr​ipt​s\a​ctivate

Leaving the virtual enviro​nment deactivate

Installing packages pip install requests

To use venv instead of virtualenv simply change virtualenv with venv while creating the virtual enviro​nment

Using Pipenv

Installing Pipenv macOS and Linux python3 -m pip install --user pipenv

Windows py -m pip install --user pipenv

Install packages from Pipfile macOS and Linux python3 -m pipenv install

Windows py -m pipenv install

Add a package macOS and Linux python3 -m pipenv install requests

Windows py -m pipenv install requests

Activating a virtual enviro​nment macOS and Linux python3 -m pipenv shell

Windows py -m pipenv shell

Leaving the virtual enviro​nment exit

When installing a package for the first time a virtual enviro​nment will be created automa​tically and it will create a Pipfile for you in your project’s
directory. The Pipfile is used to track which depend​encies your project needs in case you need to re-install them.

By Ilyes KAANICH (ilyes64) Published 4th July, 2020. Sponsored by ApolloPad.com


cheatography.com/ilyes64/ Last updated 4th July, 2020. Everyone has a novel in them. Finish
www.linkedin.com/in/ilyes- Page 1 of 1. Yours!
kaanich/ https://apollopad.com

You might also like