Skip to content

Commit e9d03b7

Browse files
committed
fix: add back the pyenv-virtualenv instructions
1 parent cf781f7 commit e9d03b7

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

MAC_SETUP.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,52 @@ This will make python and python3 point to Python 3.8.1. python2 will use 2.7.17
113113
## Python virtual environments
114114
Using [Virtual Environments](https://docs.python.org/3/library/venv.html) prevents inadvertent modifications to your global python install. Once created and sourced, calls to `python` will uses this virtual environment, not a global python install. Each virtual environment can have its own set of packages that can be different from others.
115115
116-
To create a virtual environment, run `python3 -m venv`.
116+
117+
### Using Python 3+ venv
118+
Python has builtin support for creating virtual environments, accessible by running `python -m venv`.
117119
118120
```
119121
cd python-docs-samples
120-
python3 -m venv venv-name
121-
source venv-name/bin/activate
122+
python -m venv [venv-name]
123+
source [venv-name]/bin/activate
122124
```
123125
124126
Typically you will name the venv `venv`, or `venv38` for a python 3.8 venv.
125127
128+
129+
### Using pyenv-virtualenv
130+
You can also use an extension for pyenv that will assist in managing virtual environments. This allows you to use `pyenv local` to automatically use the created virtual environment. You can install this by running `$ brew install pyenv-virtualenv`
131+
132+
1. Change to the desired source directory.
133+
134+
```console
135+
cd ~/src/python-docs-samples
136+
```
137+
138+
1. Create a virtualenv for python 3.8.1 using `pyenv virtualenv`.
139+
140+
```console
141+
pyenv virtualenv 3.8.1 python-docs-samples
142+
```
143+
144+
This creates a virtualenv folder within `~/.pyenv/versions/`.
145+
146+
1. Set the local Python version(s) with `pyenv local`
147+
148+
```console
149+
# pyenv local [name of virtualenv] [list of python versions to use]
150+
pyenv local python-docs-samples 3.8.1 3.7.6 3.6.10 3.5.9 2.7.17
151+
```
152+
153+
1. Now, when you `cd` into the source directory or a subdirectory within it,
154+
pyenv will make your virtualenv the default Python. Since you specified
155+
more than one version, it will also add binaries like `python36` and
156+
`python27` to your PATH, which nox uses when picking Python interpreters.
157+
158+
1. Add `.python-version` to your [global gitignore
159+
file](https://help.github.com/articles/ignoring-files/#create-a-global-gitignore),
160+
so it won't be committed into the repository.
161+
126162
## Nox
127163
The tests for this repository use [nox](https://github.com/theacodes/nox) for managing test runs across multiple python versions.
128164

0 commit comments

Comments
 (0)