@@ -12,10 +12,10 @@ test their code.
12
12
13
13
1 . Install [ homebrew] ( https://brew.sh/ ) if you do not already have it.
14
14
15
- ** Note:** If you are running Catalina (MacOS 10.15.x), ensure that you have a
16
- compatible version of Homebrew (2.1.13 or later). Running ` brew update ` on
15
+ ** Note:** If you are running Catalina (MacOS 10.15.x), ensure that you have
16
+ a compatible version of Homebrew (2.1.13 or later). Running ` brew update ` on
17
17
Catalina does not always result in a compatible version, so uninstall and
18
- reinstall homebrew, if necessary.
18
+ reinstall homebrew, if necessary
19
19
20
20
## Installing pyenv and pyenv-virtualenv
21
21
@@ -51,7 +51,7 @@ test their code.
51
51
## Installing multiple Python versions
52
52
53
53
54
- 1. See the available Python versions with
54
+ 1. See the available Python versions with [pyenv](https://github.com/pyenv/pyenv).
55
55
56
56
```console
57
57
pyenv install --list
@@ -88,6 +88,10 @@ test their code.
88
88
```console
89
89
$ pyenv install 3.7.6
90
90
```
91
+ * 3.8.1 (latest 3.8.x release)
92
+ ```console
93
+ $ pyenv install 3.8.1
94
+ ```
91
95
92
96
1. After you have installed a python version through pyenv,
93
97
verify that you are now using the pyenv Python shim.
@@ -97,35 +101,76 @@ test their code.
97
101
~/.pyenv/shims/python
98
102
```
99
103
104
+ ## Managing python versions using Pyenv global
105
+ Pyenv allows you to configure the priority order for your python installs.
100
106
101
- ## Using pyenv and pyenv-virtualenv to manage your Python versions
107
+ ```
108
+ pyenv global 3.8.1 3.7.6 3.6.10 3.5.9 2.7.17
109
+ ```
102
110
103
- 1. Change to the desired source directory.
111
+ This will make python and python3 point to Python 3.8.1. python2 will use
112
+ 2.7.17. You can also further specify versions, such as python3.6 to use that
113
+ version.
104
114
105
- ```console
106
- cd ~/src/python-docs-samples
107
- ```
115
+ ## Python virtual environments
116
+ Using [Virtual Environments](https://docs.python.org/3/library/venv.html)
117
+ prevents inadvertent modifications to your global python install. Once
118
+ created and sourced, calls to `python` will use this virtual environment, not
119
+ a global python install. Each virtual environment can have its own set of
120
+ packages that can be different from others.
108
121
109
- 1. Create a virtualenv using `pyenv virtualenv`.
110
122
111
- ```console
112
- pyenv virtualenv 3.7.6 python-docs-samples
113
- ```
123
+ ### Using Python 3+ venv
124
+ Python has builtin support for creating virtual environments, accessible by
125
+ running the `venv` module.
114
126
115
- This creates a virtualenv folder within `~/.pyenv/versions/`.
127
+ ```
128
+ cd python-docs-samples
129
+ python -m venv [ venv-name]
130
+ source [ venv-name] /bin/activate
131
+ ```
116
132
117
- 1. Set the local Python version(s) with `pyenv local`
133
+ Typically you will name the venv `venv`, or `venv38` for a python 3.8 venv.
118
134
119
- ```console
120
- # 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
122
- ```
123
135
124
- 1. Now, when you `cd` into the source directory or a subdirectory within it,
125
- pyenv will make your virtualenv the default Python. Since you specified
126
- more than one version, it will also add binaries like `python36` and
127
- `python27` to your PATH, which nox uses when picking Python interpreters.
136
+ ### Using pyenv-virtualenv
137
+ You can also use an extension for pyenv that will assist in managing virtual
138
+ environments. This allows you to use `pyenv local` to automatically use the
139
+ created virtual environment. You can install this by running
140
+ `$ brew install pyenv-virtualenv`
141
+
142
+ 1. Change to the desired source directory.
128
143
129
- 1. Add `.python-version` to your [global gitignore
130
- file](https://help.github.com/articles/ignoring-files/#create-a-global-gitignore),
144
+ ```console
145
+ cd ~/src/python-docs-samples
146
+ ```
147
+
148
+ 1. Create a virtualenv for python 3.8.1 using `pyenv virtualenv`.
149
+
150
+ ```console
151
+ pyenv virtualenv 3.8.1 python-docs-samples
152
+ ```
153
+
154
+ This creates a virtualenv folder within `~/.pyenv/versions/`.
155
+
156
+ 1. Set the local Python version(s) with `pyenv local`
157
+
158
+ ```console
159
+ # pyenv local [name of virtualenv] [list of python versions to use]
160
+ pyenv local python-docs-samples 3.8.1 3.7.6 3.6.10 3.5.9 2.7.17
161
+ ```
162
+
163
+ 1. Now, when you `cd` into the source directory or a subdirectory within it,
164
+ pyenv will make your virtualenv the default Python. Since you specified
165
+ more than one version, it will also add binaries like `python36` and
166
+ `python27` to your PATH, which
167
+ [nox](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#using-nox)
168
+ uses when picking Python interpreters.
169
+
170
+ 1. Add `.python-version` to your
171
+ [global gitignore file](https://help.github.com/articles/ignoring-files/#create-a-global-gitignore),
131
172
so it won't be committed into the repository.
173
+
174
+ ## More on authoring samples
175
+ If you are looking for more information on how to author samples, please view
176
+ the [Authoring Guide](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md)
0 commit comments