@@ -18,6 +18,18 @@ kernelspec:
18
18
</div>
19
19
```
20
20
21
+ <style >
22
+ .auto {
23
+ width : 70% ;
24
+ height : auto ;
25
+ }
26
+ .terminal {
27
+ width : 80% ;
28
+ height : auto ;
29
+ }
30
+ </style >
31
+
32
+
21
33
# Setting up Your Python Environment
22
34
23
35
``` {index} single: Python
@@ -50,7 +62,7 @@ Hence the best approach for our purposes is to install a Python distribution tha
50
62
1 . the core Python language ** and**
51
63
1 . compatible versions of the most popular scientific libraries.
52
64
53
- The best such distribution is [ Anaconda] ( https://www.anaconda.com/what-is-anaconda/ ) .
65
+ The best such distribution is [ Anaconda] ( https://www.anaconda.com/products/distribution ) .
54
66
55
67
Anaconda is
56
68
@@ -74,6 +86,7 @@ To install Anaconda, [download](https://www.anaconda.com/download/) the binary a
74
86
Important points:
75
87
76
88
* Install the latest version!
89
+ * Find the correct distribution for your system.
77
90
* If you are asked during the installation process whether you'd like to make Anaconda your default Python installation, say yes.
78
91
79
92
### Updating Anaconda
@@ -114,13 +127,14 @@ Because of these features, Jupyter is now a major player in the scientific compu
114
127
Here's an image showing execution of some code (borrowed from [ here] ( http://matplotlib.org/examples/pylab_examples/hexbin_demo.html ) ) in a Jupyter notebook
115
128
116
129
``` {figure} /_static/lecture_specific/getting_started/jp_demo.png
117
- :scale: 60
130
+ :figclass: auto
118
131
```
119
132
120
133
While Jupyter isn't the only way to code in Python, it's great for when you wish to
121
134
122
135
* start coding in Python
123
136
* test new ideas or interact with small pieces of code
137
+ * use powerful online interactive environments such as [ Google Colab] ( https://research.google.com/colaboratory/ )
124
138
* share or collaborate scientific ideas with students or colleagues
125
139
126
140
These lectures are designed for executing in Jupyter notebooks.
@@ -141,7 +155,7 @@ Either
141
155
If you use the second option, you will see something like this
142
156
143
157
``` {figure} /_static/lecture_specific/getting_started/starting_nb.png
144
- :scale: 60
158
+ :figclass: terminal
145
159
```
146
160
147
161
The output tells us the notebook is running at ` http://localhost:8888/ `
@@ -154,7 +168,7 @@ Thus, the Jupyter kernel is listening for Python commands on port 8888 of our lo
154
168
Hopefully, your default browser has also opened up with a web page that looks something like this
155
169
156
170
``` {figure} /_static/lecture_specific/getting_started/nb.png
157
- :scale: 60
171
+ :figclass: auto
158
172
```
159
173
160
174
What you see here is called the Jupyter * dashboard* .
@@ -166,7 +180,7 @@ Assuming all this has worked OK, you can now click on `New` at the top right and
166
180
Here's what shows up on our machine:
167
181
168
182
``` {figure} /_static/lecture_specific/getting_started/nb2.png
169
- :scale: 60
183
+ :figclass: auto
170
184
```
171
185
172
186
The notebook displays an * active cell* , into which you can type Python commands.
@@ -189,7 +203,7 @@ In this mode, whatever you type will appear in the cell with the flashing cursor
189
203
When you're ready to execute the code in a cell, hit ` Shift-Enter ` instead of the usual ` Enter ` .
190
204
191
205
``` {figure} /_static/lecture_specific/getting_started/nb3.png
192
- :scale: 60
206
+ :figclass: auto
193
207
```
194
208
195
209
(Note: There are also menu and button options for running code in a cell that you can find by exploring)
@@ -205,9 +219,10 @@ The two modes are
205
219
1 . Edit mode
206
220
* Indicated by a green border around one cell, plus a blinking cursor
207
221
* Whatever you type appears as is in that cell
222
+
208
223
1 . Command mode
209
- * The green border is replaced by a grey (or grey and blue) border
210
- * Keystrokes are interpreted as commands --- for example, typing b adds a new cell below the current one
224
+ * The green border is replaced by a blue border
225
+ * Keystrokes are interpreted as commands --- for example, typing ` b ` adds a new cell below the current one
211
226
212
227
To switch to
213
228
@@ -275,13 +290,13 @@ After this import command, functions in NumPy can be accessed with `np.function_
275
290
276
291
We can explore these attributes of ` np ` using the ` Tab ` key.
277
292
278
- For example, here we type ` np.ran ` and hit Tab
293
+ For example, here we type ` np.random.r ` and hit Tab
279
294
280
295
``` {figure} /_static/lecture_specific/getting_started/nb6.png
281
- :scale: 60
296
+ :figclass: auto
282
297
```
283
298
284
- Jupyter offers up the two possible completions, ` random ` and ` rank ` .
299
+ Jupyter offers several possible completions for you to choose from .
285
300
286
301
In this way, the Tab key helps remind you of what's available and also saves you typing.
287
302
@@ -291,35 +306,37 @@ In this way, the Tab key helps remind you of what's available and also saves you
291
306
``` {index} single: Jupyter Notebook; Help
292
307
```
293
308
294
- To get help on ` np.rank ` , say, we can execute ` np.rank ? ` .
309
+ To get help on ` np.random.randn ` , we can execute ` np.random.randn ? ` .
295
310
296
311
Documentation appears in a split window of the browser, like so
297
312
298
313
``` {figure} /_static/lecture_specific/getting_started/nb6a.png
299
- :scale: 60
314
+ :figclass: auto
300
315
```
301
316
302
317
Clicking on the top right of the lower split closes the on-line help.
303
318
319
+ We will learn more about how to create documentation like this {ref}` later <Docstrings> ` !
320
+
304
321
#### Other Content
305
322
306
323
In addition to executing code, the Jupyter notebook allows you to embed text, equations, figures and even videos in the page.
307
324
308
- For example, here we enter a mixture of plain text and LaTeX instead of code
309
-
310
- ``` {figure} /_static/lecture_specific/getting_started/nb7.png
311
- :scale: 60
312
- ```
325
+ For example, we can enter a mixture of plain text and LaTeX instead of code.
313
326
314
327
Next we ` Esc ` to enter command mode and then type ` m ` to indicate that we
315
328
are writing [ Markdown] ( http://daringfireball.net/projects/markdown/ ) , a mark-up language similar to (but simpler than) LaTeX.
316
329
317
330
(You can also use your mouse to select ` Markdown ` from the ` Code ` drop-down box just below the list of menu items)
318
331
332
+ ``` {figure} /_static/lecture_specific/getting_started/nb7.png
333
+ :figclass: auto
334
+ ```
335
+
319
336
Now we ` Shift+Enter ` to produce this
320
337
321
338
``` {figure} /_static/lecture_specific/getting_started/nb8.png
322
- :scale: 60
339
+ :figclass: auto
323
340
```
324
341
325
342
### Sharing Notebooks
@@ -414,14 +431,14 @@ By convention, these text files have a `.py` extension.
414
431
We can create an example of such a file as follows:
415
432
416
433
``` {code-cell} ipython
417
- %%file foo.py
434
+ %%writefile foo.py
418
435
419
436
print("foobar")
420
437
```
421
438
422
439
This writes the line ` print("foobar") ` into a file called ` foo.py ` in the local directory.
423
440
424
- Here ` %%file ` is an example of a [ cell magic] ( http://ipython.readthedocs.org/en/stable/interactive/magics.html#cell-magics ) .
441
+ Here ` %%writefile ` is an example of a [ cell magic] ( http://ipython.readthedocs.org/en/stable/interactive/magics.html#cell-magics ) .
425
442
426
443
### Editing and Execution
427
444
@@ -468,7 +485,7 @@ Alternatively, if you want an outstanding free text editor and don't mind a seem
468
485
469
486
## Exercises
470
487
471
- ``` {exercise}
488
+ ``` {exercise-start }
472
489
:label: gs_ex1
473
490
```
474
491
@@ -490,6 +507,10 @@ You should now be able to run a standard Jupyter notebook session.
490
507
491
508
This is an alternative way to start the notebook that can also be handy.
492
509
510
+ This can also work when you accidentally close the webpage as long as the kernel is still running.
511
+
512
+ ``` {exercise-end}
513
+ ```
493
514
494
515
``` {exercise-start}
495
516
:label: gs_ex2
@@ -519,7 +540,7 @@ There are two main flavors of Git
519
540
520
541
1 . the plain vanilla [ command line Git] ( http://git-scm.com/downloads ) version
521
542
1 . the various point-and-click GUI versions
522
- * See, for example, the [ GitHub version] ( https://desktop.github.com/ )
543
+ * See, for example, the [ GitHub version] ( https://desktop.github.com/ ) or Git GUI integrated into your IDE.
523
544
524
545
As the 1st task, try
525
546
@@ -533,9 +554,10 @@ For example, if you've installed the command line version, open up a terminal an
533
554
534
555
git clone https://github.com/QuantEcon/QuantEcon.py
535
556
```
536
-
537
557
(This is just ` git clone ` in front of the URL for the repository)
538
558
559
+ This command will download all necessary components to rebuild the lecture you are reading now.
560
+
539
561
As the 2nd task,
540
562
541
563
1 . Sign up to [ GitHub] ( https://github.com/ ) .
@@ -547,7 +569,7 @@ As the 2nd task,
547
569
For reading on these and other topics, try
548
570
549
571
* [ The official Git documentation] ( http://git-scm.com/doc ) .
550
- * Reading through the docs on [ GitHub] ( https://github.com/ ) .
572
+ * Reading through the docs on [ GitHub] ( https://docs. github.com/en ) .
551
573
* [ Pro Git Book] ( http://git-scm.com/book ) by Scott Chacon and Ben Straub.
552
574
* One of the thousands of Git tutorials on the Net.
553
575
0 commit comments