-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
2675 lines (1809 loc) · 68.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<title>Keeping an exotic pet in your home!</title>
<meta charset="utf-8" />
<meta name="author" content="Emma Rand" />
<link href="libs/remark-css/default.css" rel="stylesheet" />
<link href="libs/remark-css/rladies.css" rel="stylesheet" />
<link href="libs/remark-css/rladies-fonts.css" rel="stylesheet" />
<script src="libs/kePrint/kePrint.js"></script>
</head>
<body>
<textarea id="source">
background-image: url(pics/useR2019.png)
background-position: 4% 0%
background-size: 250px
class: inverse, right, bottom
# Keeping an exotic pet in your home!
## Taming Python to live in RStudio because<br>sometimes the best language is both!
<br>
### Emma Rand<br>[email protected]<br><br>Materials: https://github.com/3mmaRand/useR2019_tutorial
---
class: center, middle
# But first.....Who am I? <br> and some Thank yous!
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Who I am?
.pull-left[
![York Lower Petergate with the cathedral in the background](https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Lower_Petergate_in_York%2C_England.jpg/324px-Lower_Petergate_in_York%2C_England.jpg)
]
.pull-right[
Lecturer (Assistant Professor), Department of Biology University of York, UK
I'm a biologist by training.
Long time R user, relatively new to Python.
<br>
<br>
<br>
<br>
⬅️ York, twinned with Dijon.
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
]
---
background-image: url(pics/member_institute_logos.png)
background-position: 95% 7%
# Thank yous!
## To the local organisation committee
<small>
* Nathalie Vialaneix (chair), MIAT, INRA
* Sébastien Déjean (vice-chair), Institut de Mathématiques de Toulouse, Université Toulouse 3 Paul Sabatier
* Anne Ruiz-Gazen (vice-chair), Toulouse School of Economics, Université Toulouse 1 Capitole
* Heather Turner (vice-chair), statistical consultant and associate fellow of the Statistics Department at the University of Warwick
* Aurore Archimbaud, Toulouse School of Economics
* Christophe Bontemps, Toulouse School of Economics, INRA
* Robert Faivre, MIAT, INRA
* Xavier Gendre, Institut de Mathématiques de Toulouse, Université Toulouse 3 Paul Sabatier
* Thibault Laurent, Toulouse School of Economics, CNRS
* Élise Maigné, Observatoire du Développement Rural, INRA
* Pierre Neuvial, Institut de Mathématiques de Toulouse, CNRS
* Rémi Servien, InTheRes, INRA
* Matthias Zytnicki, MIAT, INRA
</small>
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Thank yous!
## For funding
.pull-left[
To the organisers and their sponsers
![useR2019 logo](pics/useR2019.png)
]
.pull-right[
![r consortium logo](pics/r_consortium.png)
My institution
![University of York logo](pics/UoY-logo.png)
]
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
background-image: url(pics/leila.jpg)
background-position: 90% 50%
background-size: 400px
# Thank yous!
## Leila Khajavi
.pull-left[
Leila is an American pursuing her PhD in Bioinformatics here in Toulouse, affiliated with both MIAT (INRA) and CPTP (INSERM).
She is very kindly giving her time here today to help out and has already contributed to the session by going through the material and giving some feedback.
But any errors that remain are mine!
]
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Thank yous!
My colleagues at the University of York allowed me to practice on them:
James Chong
Bryden Fields
Martina Stoycheva
Jack Law
Oliver Noble
Rebecca Hall
Evie Farnham
Mike Gray
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
--
And finally...
--
## Everyone here for coming! 😄
---
<iframe src="https://docs.google.com/forms/d/e/1FAIpQLSdHXFrhsSfUXEyIhHAnP40fH5a66eRZm3YZaEcNFT-F08CKjA/viewform?embedded=true" width="640" height="650" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/f/f8/Python_logo_and_wordmark.svg)
background-position: 95% 95%
background-size: 250px
# Why `reticulate`?
You finally found the **perfect** solution to a data problem!
😁
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
--
but it's written in Python
😬
--
You're collaborating with some great people
😁
--
but they mainly use Python!
😬
You want to use existing/available solutions and collaborate more easily.
---
# Why `reticulate`?
You could move to the darkside 🐍...
--
But you're familiar 💙 with R...
![R logo](pics/R_logo.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
But you're familiar with R
**and very at home in RStudio...**
&nbsp;
&nbsp;
&nbsp;
![cartoon house labelled RStudio](pics/house.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
But you're familiar with R
and very at home in RStudio
**because it's comfortable...**
&nbsp;
&nbsp;
![cartoon house labelled RStudio with sleeping cat](pics/house_cat.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
But you're familiar with R
and very at home in RStudio
because it's comfortable
**and has many tools you like...**
&nbsp;
![cartoon house labelled RStudio with sleeping cat and tidyverse hex stickers](pics/house_cat_tools.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
But you're familiar with R
and very at home in RStudio
because it's comfortable
and has many tools you like
**and the sun always shines!**
![cartoon house labelled RStudio with sleeping cat and tidyverse hex stickers in the sun](pics/house_cat_tools_sun.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
So even though Python has some great tools...
&nbsp;
&nbsp;
&nbsp;
&nbsp;
![cartoon house labelled RStudio with sleeping cat and tidyverse hex stickers in the sun](pics/house_cat_tools_sun.png)![cartoon house labelled python](pics/house_python.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
So even though Python has some great tools
**and some very cool people...**
&nbsp;
&nbsp;
&nbsp;
![cartoon house labelled RStudio with sleeping cat and tidyverse hex stickers in the sun](pics/house_cat_tools_sun.png)![cartoon house labelled python with cool cat](pics/house_python_cat.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
So even though Python has some great tools
and some very cool people
**you don't want to move in!**
&nbsp;
&nbsp;
![cartoon house labelled RStudio with sleeping cat and tidyverse hex stickers in the sun](pics/house_cat_tools_sun2.png)![cartoon house labelled python with cool cat](pics/house_python_cat.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why `reticulate`?
Thankfully, there's `Reticulate`
<small>JJ Allaire, Kevin Ushey and Yuan Tang (2018). reticulate: Interface to 'Python'. R package version 1.10. https://CRAN.R-project.org/package=reticulate </small>
&nbsp;
![RStudio and Pythonhouses joined by the reticulate package logo](pics/house_reticulate.png)
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
class: inverse, center, middle
# Tutorial Overview
---
# Tutorial Overview 🗺
* Context: Very brief background to R 💙and Python 🐍
* Rationale: why use [Reticulate](https://rstudio.github.io/reticulate), what are its key features, how can it be used and set up
* Background: A little Python. Only what you need to start making sense of calling Python from R
* Using Python interactively with `repl_python()`
* Integration in R markdown 🖋: Writing your own `reticulate` tutorial
* Part 1: Building your understanding
* Part 2: Classifying audio segments
What the tutorial won't be: a thorough introduction to Python, R Markdown or machine learning.
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
<iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfFYrr2fN0fVRoKl0yvZUJSM3FwEZuO3ZzKLfqXtT6XvJumvQ/viewform?embedded=true" width="640" height="600" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
---
# Aims
This tutorial was designed for:
* beginner to intermediate R users
* those with little to no experience of Python
* those who may not have experience of Rmarkdown
--
By the end of the tutorial you should be able to:
* pass objects between simultaneous R and Python sessions
* use Python methods in R code
* incorporate Python snippets in to your R workflow even if you don't understand in detail how they work
As long as you know what the Python methods and code snippets are for, and have a good-enough understanding of their inputs and outputs, then you can use `reticulate`.
--
Some of the code is specifically designed to develop understanding of the integration rather than reflect a workflow. The later section comprises an example workflow.
---
# Background
<table>
<thead>
<tr>
<th style="text-align:left;"> </th>
<th style="text-align:left;"> R </th>
<th style="text-align:left;"> Python </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Released </td>
<td style="text-align:left;"> 1995 </td>
<td style="text-align:left;"> 1991 </td>
</tr>
<tr>
<td style="text-align:left;"> Author </td>
<td style="text-align:left;"> Ihaka &amp; Gentleman, Chambers </td>
<td style="text-align:left;"> van Rossum </td>
</tr>
<tr>
<td style="text-align:left;"> Purpose </td>
<td style="text-align:left;"> User-friendly data analysis and visualisation for 'non-programmers' </td>
<td style="text-align:left;"> Object-oriented,
Readable, general purpose programming language </td>
</tr>
<tr>
<td style="text-align:left;"> Users most likely to be </td>
<td style="text-align:left;"> Statistics graduates, Academics, data scientists </td>
<td style="text-align:left;"> Computer Science graduates, Software engineers </td>
</tr>
<tr>
<td style="text-align:left;"> Features </td>
<td style="text-align:left;"> R Markdown, tidyverse </td>
<td style="text-align:left;"> Integration with web aps, Unified Machine learning API </td>
</tr>
</tbody>
</table>
.footnote[
Materials: https://github.com/3mmaRand/useR2019_tutorial
]
---
# Why use Reticulate
## Speed up your workflow
* Problem solving is the defining feature of a data scientist
* Language should be secondary
* Choice of language driven by early impressions of the data. Change in direction later means lost time in translating
## Facilitate collaboration
* Allows you to leverage the skills expertise of the whole team
* Solves the hardest problem in Data Science - People<sup>1</sup>.
* Many Data Scientists know both and they are happier<sup>2</sup>
.footnote[
[1] Mangano, 2019
[2] Stack Overflow Developers' Survey, NanoMathius, 2018
]
---
# Reticulate
## Key features
1. Ability to call Python from R
2. Translation between R objects and Python objects
3. Flexible binding to different Python environments
---
# Reticulate
## Alllows you to use Python in four ways:
1. Interactively in the console: `repl_python()`
2. Sourcing Python scripts
3. Importing Python modules
4. In R Markdown documents
--
We will start with `repl_python()` to build our understanding.
Then use R Markdown.
---
# Reticulate
## Ingredients
You will need
* [RStudio 1.2](https://www.rstudio.com/products/rstudio/)
1.2 is needed for some of the most useful features
--
* Python
[Anaconda 3](https://www.anaconda.com/distribution/)
recommended for data science, includes many useful libraries.
--
* The `reticulate` package. I recommend using the development version
```r
devtools::install_github("rstudio/reticulate")
```
.centre[
![reticulate-logo](pics/reticulated_python.png)
]
---
background-image: url(https://upload.wikimedia.org/wikipedia/en/c/cd/Anaconda_Logo.png)
background-position: 10% 30%
background-size: 280px
# This one
--
.pull-right[
![snake](pics/anconda-1.jpg)
**Not this one**
]
---
# Reticulate
## You will also need
* Any other Python modules your Python code depends on (not needed here)
--
* Probably / possibly.....to set to the QT_PLUGIN_PATH environment variable.
In windows: Control Panel -> System and Security -> System then
Advanced System settings -> Environment variables
I have set mine to:
`C:\Program Files\RStudio\bin\plugins; C:\ProgramData\Anaconda3\Library\plugins`
.footnote[
If you can describe and resolve in a better but still minimal way, please get in touch!
]
---
# Reticulate
## In windows: QT_PLUGIN_PATH environment variable
![ QT_PLUGIN_PATH environment variable in Advanced System settings](pics/env_variables.png)
---
# Reticulate
## In windows: QT_PLUGIN_PATH environment variable
If you get this error:
.pull-left[
**This application has failed to start because it could not find or load the qt platform plugin "windows" in "" **
]
.pull-right[
![](pics/QT_error.png)
]
Setting the QT_PLUGIN_PATH environment variable as on the previous slide should fix it.
.footnote[
If you can describe and resolve in a better but still minimal way, please get in touch!
]
---
class: inverse, center, middle
# A little Python
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
Suppose you wanted to created an array of 5 numbers.
In R you might do this as:
```r
r_array <- c(4, 5, 1, 6, 8)
```
--
In Python you might use a list<sup>1</sup>
A list is created like this:
```python
python_list = [4, 5, 1, 6, 8]
```
.footnote[
[1] Python doesn't have a native array data structure
]
--
Python uses `=` for assignment
--
The square brackets denote a list
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
But lists do not behave as a R user might expect.
For example, what would you expect the output to be?
```python
python_list = [4, 5, 1, 6, 8]
*python_list * 2
```
--
This?
```python
python_list = [4, 5, 1, 6, 8]
python_list * 2
*[8, 10, 2, 12, 16]
```
--
Infact it is this:
```python
python_list = [4, 5, 1, 6, 8]
python_list * 2
*[4, 5, 1, 6, 8, 4, 5, 1, 6, 8]
```
😲
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
Instead you might use the [NumPy package](http://www.numpy.org/)<sup>1</sup>. NumPy arrays behave like R vectors/arrays.
.footnote[
[1] NumPy is the fundamental package for scientific computing with Python. It is part of the
SciPy ecosystem.
Jones E, Oliphant E, Peterson P, et al. SciPy: Open Source Scientific Tools for Python, 2001-, http://www.scipy.org/.
]
--
To make a NumPy array we need to first`import` NumPy, then use it's `array()` function.
This is going to introduce us to several Pythonesque things.
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
The Python code looks like this:
```python
import numpy as np
python_array = np.array([4, 5, 1, 6, 8])
```
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
The Python code looks like this:
```python
*import numpy as np
python_array = np.array([4, 5, 1, 6, 8])
```
`import` in Python is the equivalent of `library()` in R
--
To use methods in NumPy (and other modules) we need to use the "dot" notation:
`numpy.method_name()`
To make this quicker to type it is common to use an alias. That's the `as np` bit
---
background-image: url(pics/cute-snake.jpg)
background-position: 95% 7%
# Python fundamentals
```python
import numpy as np
*python_array = np.array([4, 5, 1, 6, 8])
```
The second line of code creates the numpy array (from a list).
--
To do things with `python_array` we might use a built-in function. These are used in a way that will be familar to you, for example:
```python
type(python_array)
<class 'numpy.ndarray'>
```
--
Python also has methods. Methods are called on objects with the dot notation.
For example:
```python
python_array.max()
8
```
---
class: center, middle
# Enough!<br> <br>Let me code
## We will cover some more Python as we go through the tutorial.
---
class: inverse, center, middle
# Using Python in the console
## `reticulate::repl_python()`
---
# Using Python in the console
## Steps
We are going to use Python interactively in the console.
We will
* Create a new project
* Check our Python environment
* Start a Python session from our R session
* Create a NumPy array
* Use the NumPy array
* find its size (an attribute)
* calculate its mean (a method)
* End the Python session
* Access the NumPy array from our R session
.footnote[
<span style=" font-weight: bold; color: white !important;border-radius: 4px; padding-right: 4px; padding-left: 4px; background-color: purple !important;" >Extra exercise</span> Indicates an optional extra exercise to try while you're waiting for me to move on.
]
---
# Using Python in the console
## Organising ourselves
.pull-left[
We are going to work in a project<sup>1</sup>.
File | New Project | Existing Directory
Choose Browse
And navigate to the "music_ml" folder and Open
]
.pull-right[
![rstudio's Create Project from Existing Directory window](pics/new_project.png)
]
Choose Create Project
.footnote[
[1] New to projects? [RStudio: Using Projects](https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects)
]
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
We are going to be moving between Python and R sessions.
Which could get confusing!
--
What session you are in **at the start of a slide** is indicated like this:
.pull-left[
## 🐍 _Sub-heading_
You are working interactively with python and your prompt should look like this:
```r
>>>
```
You may **finish** the slide in an R session
]
--
.pull-right[
## 💙 _Sub-heading_
You are working interactively with R and your prompt should look like this:
```r
>
```
You may **finish** the slide in a Python session
]
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 💙 Prepare to start a Python session
Load the reticulate package
```r
> library(reticulate)
```
For this section on using `repl_python()` I will show the prompt, either `>` or`>>>` in the code.
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 💙 Start a Python session
With `repl_python()`:
```r
> repl_python()
Python 3.7.3 (C:\PROGRA~3\ANACON~1\python.exe)
Reticulate 1.12.0.9003 REPL -- A Python interpreter in R
>>>
```
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 🐍 repl_python()
```r
> repl_python()
*Python 3.7.3 (C:\PROGRA~3\ANACON~1\python.exe)
*Reticulate 1.12.0.9003 REPL -- A Python interpreter in R
>>>
```
* You get a message to tell you what version of Python you're using and where it is
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 🐍 repl_python()
```r
> repl_python()
Python 3.7.3 (C:\PROGRA~3\ANACON~1\python.exe)
Reticulate 1.12.0.9003 REPL -- A Python interpreter in R
*>>>
```
* You get a message to tell you what version of Python you're using and where it is.
* `>>>` indicates the Python prompt.
--
We need to use Python 3.
By default, `reticulate` uses the version of Python found on your PATH.
--
If Python 3 is not being used (possibly Mac users) we can change it.
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 🐍 Change the Python version.
It is not necessary to do this if you're already using Python 3 but it won't hurt if you do.
End the `repl_python` session:
```r
>>> exit
>
```
--
## 💙
Set the version of Python you want to use.
This needs to be where Anaconda3 installed. In my case:
```r
> use_python("C:/ProgramData/Anaconda3/python.exe")
```
---
background-image: url(pics/reticulated_python.png)
background-position: 95% 7%
# Using Python in the console
## 💙 Check the Python version
Confirm it has been set:
```r
> Sys.which("python")
python
"C:\\PROGRA~3\\ANACON~1\\python.exe"
```
On windows machines the paths will be short paths (8+3 components, no spaces) with \ as the path delimiter.
In my case, it is short for `C:/ProgramData/Anaconda3/python.exe`
So I know I'm using Python 3