Skip to content

Commit 7598779

Browse files
committed
fix: Update MAC_SETUP to describe using builtin venv
1 parent 0cf596f commit 7598779

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

MAC_SETUP.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test their code.
5151
## Installing multiple Python versions
5252

5353

54-
1. See the available Python versions with
54+
1. See the available Python versions with [pyenv](https://github.com/pyenv/pyenv),=.
5555

5656
```console
5757
pyenv install --list
@@ -88,6 +88,10 @@ test their code.
8888
```console
8989
$ pyenv install 3.7.6
9090
```
91+
* 3.8.1 (latest 3.8.x release)
92+
```console
93+
$ pyenv install 3.8.1
94+
```
9195

9296
1. After you have installed a python version through pyenv,
9397
verify that you are now using the pyenv Python shim.
@@ -97,19 +101,46 @@ test their code.
97101
~/.pyenv/shims/python
98102
```
99103

104+
## Managing python versions using Pyenv global
105+
Pyenv allows you to configure the prioirty order for your python installs.
106+
107+
```
108+
pyenv global 3.8.1 3.7.6 3.6.10 3.5.9 2.7.17
109+
```
110+
111+
This will make python and python3 point to Python 3.8.1. python2 will go to 2.7.17. You can also further specify versions, such as python3.6 to use that version.
112+
113+
## Python virtual environments
114+
Using Virtual Environments is fairly common across the Python community. While there is built in support in python for creating environments, there are also other tools that the community has embraced. Option 1 relies on python itself, Option 2 uses an additional tool that some users may prefer.
115+
116+
In either case, you can create and source virtual environments, `python` will point to this virtual environment, not a global python install. Each virtual environment can have its own set of packages that can be different from others.
117+
118+
119+
### Option 1: Using builtin support, venv
120+
Python ships with support of its own to create virtual environments. You can [create a virtual environment](https://docs.python.org/3/library/venv.html).
121+
122+
```
123+
cd python-docs-samples
124+
python3 -m venv venv-name
125+
source venv-name/bin/activate
126+
```
127+
128+
Typically you will name the venv `venv`, or `venv38` for a python 3.8 venv.
129+
100130
101-
## Using pyenv and pyenv-virtualenv to manage your Python versions
131+
## Option 2: Using pyenv-virtualenv to manage your Python versions
132+
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 create virtual environment
102133
103134
1. Change to the desired source directory.
104135
105136
```console
106137
cd ~/src/python-docs-samples
107138
```
108139
109-
1. Create a virtualenv using `pyenv virtualenv`.
140+
1. Create a virtualenv for python 3.8.1 using `pyenv virtualenv`.
110141
111142
```console
112-
pyenv virtualenv 3.7.6 python-docs-samples
143+
pyenv virtualenv 3.8.1 python-docs-samples
113144
```
114145
115146
This creates a virtualenv folder within `~/.pyenv/versions/`.
@@ -118,7 +149,7 @@ test their code.
118149
119150
```console
120151
# pyenv local [name of virtualenv] [list of python versions to use]
121-
pyenv local python-docs-samples 3.6.10 3.7.6 3.5.9 2.7.17
152+
pyenv local python-docs-samples 3.8.1 3.7.6 3.6.10 3.5.9 2.7.17
122153
```
123154
124155
1. Now, when you `cd` into the source directory or a subdirectory within it,

0 commit comments

Comments
 (0)