Cheatography
https://cheatography.com
A virtual environment 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.
What is a virtual environment?
A virtual environment 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 Environment 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 virtualenv. Useful when using multiple virtualenv directories. |
pipenv |
Less popular, It automatically creates and manages a virtualenv for your projects by combining Pipfile, pip and virtualenv into one command on the command-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 environment |
macOS and Linux |
python3 -m virtualenv my-env
|
|
Windows |
|
Activating a virtual environment |
macOS and Linux |
source my-env/bin/activate
|
|
Windows |
.\my-env\Scripts\activate
|
Leaving the virtual environment |
|
|
Installing packages |
|
|
To use venv instead of virtualenv simply change virtualenv with venv while creating the virtual environment
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 |
|
Add a package |
macOS and Linux |
python3 -m pipenv install requests
|
|
Windows |
py -m pipenv install requests
|
Activating a virtual environment |
macOS and Linux |
|
|
Windows |
|
Leaving the virtual environment |
|
exit |
When installing a package for the first time a virtual environment will be created automatically and it will create a Pipfile for you in your project’s directory. The Pipfile is used to track which dependencies your project needs in case you need to re-install them.
|
Created By
https://www.linkedin.com/in/ilyes-kaanich
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by ilyes64