-
Notifications
You must be signed in to change notification settings - Fork 9
Setup and use Python’s (v3.x) virtual environments using pyvenv
Michael Hulse edited this page Nov 14, 2019
·
2 revisions
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.
Assuming you’re using Homebrew as a package manager.
Install Python:
$ brew install python3Create the “FOO” environment:
$ pyvenv ~/.virtualenvs/FOOActivate:
$ source ~/.virtualenvs/FOO/bin/activateDeactivate (when activated):
$ deactivateNote, pip comes with Python 3.4 pyvenv:
$ which pip
~/.virtualenvs/FOO/bin/pipNice!
To make activation quick, add an alias to your .bash_profile:
# Simplify pyvenv activation for "FOO" environment:
alias FOO='source ~/.virtualenvs/gutenberg/bin/activate'And then reload:
source ~/.bash_profileNow:
$ FOO… which activates your “FOO” virtual environment; now you can install packages, using pip, into your environment’s site-packages.