-
Notifications
You must be signed in to change notification settings - Fork 24
/
tp.qmd
118 lines (80 loc) · 5.29 KB
/
tp.qmd
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
---
title: Integrated Development Environment
title-short: Short title
---
An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools and a debugger.
## Python's specific IDE
There are many IDEs for Python, but none are perfect, and there is no consensus in the Python community. There is no real "canonical" choice as Rstudio is **the one** for `R` users.
As Python is a real jackknife programming language, depending on your goal (data scientific program, web development, etc.) you may choose a specific IDE for a particular task.
- Scientific computing: [Pyzo](https://pyzo.org/), [Spyder](https://www.spyder-ide.org/)
- Generic: [PyCharm](https://www.jetbrains.com/pycharm/), [VSCode](https://code.visualstudio.com/)
We warmly recommend you use an IDE, and we will mostly describe VSCode in what follows.
## VSCode/Codium
For instance, you can use `VSCode`. This is a powerful, cross-platform IDE that comes with many extensions.
On the FdS-Linux box, there is a fork of `VSCode` called `vscodium`.
You may launch it via the GUI or through the following command line
```bash
$ vscodium
```
or
```bash
$ code
```
### Install a VSCode extension
We will install the Python extension.
To install it:
1. Open VSCode.
2. Open the Extensions tab (left bar of the VSCode window or simply press `Ctrl+Shift+X`)
3. Type Python to find the Python extension from Microsoft
4. Click the `Install` button, then the `Enable` button
or
1. Open VSCode
2. Press `Ctrl+P` to open the Quick Open dialog
3. Type `ext install ms-python.python` to find the extension
4. Click the `Install` button, then the `Enable` button
or
1. Run in a terminal
```bash
$ vscodium --install-extension ms-python.python
```
::: {.callout-important appearance='default' icon="false"}
## EXERCISE: Installation on your machine
1. Install the Python extension in your VSCode
:::
### An advanced text editor
The `keyboard shortcuts Reference guide` is available in the `help` menu (or with `Ctrl+K Ctrl+R` shortcut).
It can be very useful to learn some shortcuts.
For instance:
- Learn how **multicursors** work (*e.g.,* search for an occurrence with `Ctrl+d`)
- Create aligned **multicursors** with `Ctrl+Shift`
- Learn how to move an entire line with `Alt+up`
- etc.
### Using VSCode as a Python IDE
*Reference:* [VSCode docs for Python](https://code.visualstudio.com/docs/python/python-tutorial)
This part is dedicated to setting up `VSCode` to use it as a Python IDE. You should have a working `VSCode` (with Python extension) and `anaconda` program.
::: {.callout-important appearance='default' icon="false"}
## EXERCISE: VSCode and Python
1. Start VSCode in a project (workspace) folder: Using a command prompt or terminal, create an empty folder called `test_dir`, navigate into it, and open VSCode (`vscodium`) in that folder (`.`) by entering the following commands:
```bash
cd ~
mkdir test_dir
cd hello
code
```
**Note:** If you're using an Anaconda distribution, be sure to use an Anaconda command prompt.
By starting VSCode in a folder, that folder becomes your "workspace". VSCode stores settings that are specific to that workspace in the (hidden) subfolder `.vscode/settings.json`, which are separate from user settings that are stored globally.
Alternatively, you can run VSCode through the operating system UI, then use `File > Open Folder` to open the project folder.
2. Select a Python interpreter: Python is an interpreted language; to run Python code, you must tell VSCode which interpreter to use.
From within VSCode, select a Python 3 interpreter by opening the Command Palette (`Ctrl+Shift+P`), start typing the `Python: Select Interpreter` command to search, then select the command. You can also use the `Select Python Environment` option on the Status Bar if available
3. Open the terminal in VSCode and download with `wget` or `curl` the file `test_python.py` [here](https://raw.githubusercontent.com/josephsalmon/HAX712X/main/Courses/IDE/test_python.py). Run it through the IDE.
4. Next, you have to learn how to debug a simple Python script, see the [VSCode help on debugging](https://code.visualstudio.com/docs/python/debuggings) for that.
:::
## Recommended extensions for VS Code
- Python: [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- Markdown: [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
- linter/flake8: [cornflakes](https://marketplace.visualstudio.com/items?itemName=kevinglasson.cornflakes-linter)
- Spell check: [Grammarly](https://marketplace.visualstudio.com/items?itemName=znck.grammarly), [SpellChecker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) or [LTex](https://marketplace.visualstudio.com/items?itemName=valentjn.vscode-ltex)
- [Live Share](https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare) to collaboratively edit and debug with others in real-time, regardless of your programming language.
- [Quarto](https://marketplace.visualstudio.com/items?itemName=quarto.quarto)
- LaTeX: [LaTeX Workshop](https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop)
- etc.