-
Notifications
You must be signed in to change notification settings - Fork 4
/
environPy.qmd
169 lines (105 loc) · 8.82 KB
/
environPy.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
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
---
output:
html:
code_fold: true
---
# Python {.unnumbered}
To run the analysis and reproduce the code in Python, you will need to set up the Python environment to:
- Execute the [Jupyter Notebooks](https://docs.jupyter.org/en/latest/) of the Lab sessions of the course.
- Prepare your own Jupyter Notebooks for the assignments.
::: callout-important
**Do not** try to run Python code in RStudio. Only run in Jupyter Notebooks (.ipynb) with the Python environment provided.
:::
We will use `Miniconda` to handle our working environment.
## Set up Miniconda (and Python) on Ms Windows {.unnumbered}
### Installation {.unnumbered}
1. Install Miniconda:
- **Option 1**: On a UoL Machine: Anaconda is installed on many university machines. Please check whether it is installed. If not, download and install Anaconda through from `Install University Applications`, type and choose `Anaconda`.
- **Option 2**: *Recommended* - Install Miniconda on your personal Laptop: Follow the instructions [here](https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html).
2. During the installation, leave the default settings. In particular, when asked whom to "Install Miniconda for", choose "Just for me".
::: callout-caution
## University Machines
If you do choose to work on University Machines
1. Chose a machine where Anaconda has been pre-installed.
2. Always use the same machine. For example if on the first day you are using CT60 Station 17 - Orange Zone, continue using this machine for the rest of the course. If you change machine you will need to re-install the environment every time.
:::
### Set up the Directories {.unnumbered}
1. Create a folder where you want to keep your work conducted throughout this course. For example, call it `envs363_563`. You can save it wherever you want. If you are working on a university machine, it could be worth creating it in `M:/`, which is your "virtual" hard-disk.
<img src="./img/Step1_py.PNG" width="90%"/>
2. Download the [data](https://github.com/pietrostefani/gds/tree/main/data) to run and render the jupyter notebooks. To learn how to download folders from github see [here](https://pietrostefani.github.io/gds/download.html).
3. Unzip the folders and move the nested folders into the folder `envs363_563`.
4. Create another folder called `labs`
The folder structure should look like:
```
envs363_563/
├── data/
└── labs/
```
### Set up the Python Environment {.unnumbered}
1. Download the `envs363_563.yml` from GitHub by cliciking `Download raw file`, top right [at this page](https://github.com/pietrostefani/gds/blob/main/envs363-563.yml)
2. Save it in the folder `envs363_563` created before.
3. Type in the search bar and find the `Anaconda Powershell Prompt` if working on University Machine or `Anaconda Prompt (miniconda 3)` if on your personal. Launch it. The terminal should appear.
<img src="./img/Step2_py.jpeg" width="60%"/>
3. In the **Anaconda Terminal** write: `conda env create -n envs363_563 --file M:\envs363\envs363_563.yml` and press `Enter`; if the file is located elsewhere you'll need to use the corresponding file path.
4. If you are prompted any questions, press `y`. This process will install all the packages necessary to carry out the lab sessions.
5. In the **Anaconda Terminal** write `conda activate envs363_563` and press `Enter`. This activates your working environment.
<img src="./img/environ_Py_8.png" width="50%"/>
<img src="./img/Step3_py.PNG" width="80%"/>
6. *Necessary* on University machines, otherwise *Optional*: Configuration of Jupyter Notebooks
- In the **Anaconda Terminal**, write `jupyter server --generate-config` and press enter. This, at least in Windows, should create a file to: `C:\Users\username\.jupyter\jupyter_server_config.py`.
- Open the file with a text editor (e.g. [Notepad++](https://notepad-plus-plus.org)), do a `ctrl-f` search for: `c.ServerApp.root_dir`, uncomment it by removing the \# and change it to `c.ServerApp.notebook_dir = 'M:\\your\\new\\path`, for example the directory where you created the `envs363_563` folder. In the University Machines, it is advised to work on the directory `M:\`.
- Save the file and close it.
<img src="./img/Step4_py.PNG" width="80%"/>
### Start a Lab Session {.unnumbered}
1. Download the Jupyter Notebook of the session in your folder. Choose one jupyter notebook and click `Dowload raw file` as shown below.
<img src="./img/Step5_py.PNG" width="80%"/>
2. Save the file in the `labs` folder within your `envs363_563` folder on your machine.
3. Type in the search bar, find and open the `Anaconda Prompt (miniconda 3)`.
4. In the **Anaconda Terminal** write and run `conda activate envs363_563`.
5. In the **Anaconda Terminal** write and run `jupyter notebook`. This should open Jupyter Notebook in your default browser.
<img src="./img/Step6_py.PNG" width="80%"/>
6. Navigate to your course folder in and double click on the notebook downloaded in step 1.
7. You can now work on your copy of the notebook.
Follow these instructions and test your installation **prior to the first Lab Session**. If you experience any issues, write a message on the Ms Teams channel of the module. Setting up the Python environment is necessary for:
- Executing the [Jupyter Notebooks](https://docs.jupyter.org/en/latest/) of the Lab sessions of the course.
- Preparing your own Jupyter Notebooks for the assignments (one each).
## Set up Miniconda (and Python) on MAC {.unnumbered}
### Installation {.unnumbered}
To install Miniconda on your personal laptop, Follow the instructions [here](https://docs.conda.io/projects/miniconda/en/latest/miniconda-install.html). During the installation, leave the default settings. In particular, when asked whom to "Install Miniconda for", choose "Just for me".
### Set up the Directories {.unnumbered}
1. Create a folder where you want to keep your work conducted throughout this course. For example, call it `envs363_563`. You can save it wherever you want. For example, Elisabetta has named her folder `envs363_563` and it's in her Dropbox in `Users/PIETROST/Library/CloudStorage/Dropbox/envs363_563`
2. Download the [data](https://github.com/pietrostefani/gds/tree/main/data) to run and render the jupyter notebooks. To learn how to download folders from github see [here](https://pietrostefani.github.io/gds/download.html).
3. Unzip the folders and move the nested folders into the folder `envs363_563`.
4. Create another folder called `labs`
The folder structure should look like:
```
envs363_563/ ├── data/ └── labs/
```
<img src="./img/environ_Py_5.png" width="80%"/>
### Set up the Python Environment {.unnumbered}
1. Download the `envs363_563.yml` from GitHub by clicking `Download raw file`, top right [at this page](https://github.com/pietrostefani/gds/blob/main/envs363-563.yml)
2. Save it in the folder `envs363_563` created before.
3. Type in the search bar and open the **Terminal**.
4. In the **Terminal** write `conda env create -n envs363 --file envs363_563.yml` and press `Enter`. This will need to be modified according to where you placed the `envs363_563` folder. For example, Elisabetta has named her folder `envs363_563` and it's in her Dropbox in `Users/PIETROST/Library/CloudStorage/Dropbox/envs363_563/envs363_563.yml`. If you created the `envs363_563` folder on your desktop, the path would be `Desktop/envs363_563`.
<img src="./img/environ_Py_6.png" width="100%"/>
4. If you are prompted any questions, press `y`. This process will install all the packages necessary to carry out the lab sessions.
5. You should then see this
<img src="./img/environ_Py_8.png" width="50%"/>
### Start a Lab Session {.unnumbered}
1. Download the Jupyter Notebook of the session in your folder. Choose one jupyter notebook and click `Dowload raw file` as shown below
<img src="./img/environ_Py_11.png" width="80%"/>
2. Save the file in the `labs` folder within your `envs363` folder on your machine.
3. Type in the search bar, find and open the **Terminal**.
4. In the **Terminal** write and run `conda activate envs363`.
5. In the **Terminal** write and run `jupyter notebook`.
<img src="./img/environ_Py_7.png" width="90%"/>
6. This should open Jupyter Notebook in your default browser. You should see something like this:
<img src="./img/environ_Py_9.png" width="80%"/>
7. Navigate to your folder. You can now work on your copy of the notebook.
<img src="./img/environ_Py_10.png" width="80%"/>
## Py Basics
Please refer to the tutorials from [learnpython.org](https://www.learnpython.org/en/Welcome) for an introduction to coding in Python. We particularly recommend the tutorials listed under the "Learn the Basics" section.
## Resources
Some help along the way with:
1. [Geographic Data Science with Python](https://geographicdata.science/book/intro.html).
2. [Python for Geographic Data Analysis](https://pythongis.org/index.html)