Skip to content

Commit e4a7de3

Browse files
committed
config uv setup
1 parent bf22017 commit e4a7de3

2 files changed

Lines changed: 244 additions & 155 deletions

File tree

learners/setup.md

Lines changed: 47 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -18,161 +18,84 @@ Now you should have the following files in the `data` directory:
1818

1919
## Software Setup
2020

21-
### Installing Python Using Anaconda
21+
[Python](https://python.org) is a popular language for scientific computing, and great for
22+
general-purpose programming as well. There are many ways to install Python and the
23+
required dependencies. In this workshop, we will use [`uv`](https://docs.astral.sh/uv/)
24+
for its fast and easy installation process.
2225

23-
[Python][python] is a popular language for scientific computing, and great for
24-
general-purpose programming as well. Installing all of its scientific packages
25-
individually can be a bit difficult, however, so we recommend the all-in-one
26-
installer [Anaconda][anaconda].
26+
:::::::::::::::::::::::::::::::::::::::discussion
27+
28+
### Software Setup using uv
29+
30+
Please follow the instructions below according to your operating system.
2731

2832
Regardless of how you choose to install it, please make sure you install Python
29-
version 3.x (e.g., 3.9 is fine). Also, please set up your python environment at
30-
least a day in advance of the workshop. If you encounter problems with the
33+
version 3.x (e.g., 3.12 is fine). Also, please set up your python environment at
34+
least a day in advance of the workshop. If you encounter problems with the
3135
installation procedure, ask your workshop organizers via e-mail for assistance so
3236
you are ready to go as soon as the workshop begins.
3337

34-
::::::::::::::::::::::::::::::::::::::: discussion
35-
36-
### Installing Anaconda
37-
3838
:::::::::::::::::::::::::::::::::::::::::::::::::::
3939

4040
:::::::::::::::: solution
4141

42-
### Windows
43-
44-
[Video tutorial][video-windows]
45-
46-
1. Open [https://www.anaconda.com/download][anaconda-windows] with your web browser.
42+
### Linux / MacOS
4743

48-
2. Download the Anaconda for Windows installer with Python 3.
49-
50-
3. Install Python 3 by running the Anaconda Installer, using all of the defaults for installation *except* make sure that:
51-
* **Register Anaconda as my default Python 3.x** option is checked (it should be in the latest version of Anaconda).
52-
* **Add Anaconda to my PATH environment variable** is selected.
53-
54-
55-
:::::::::::::::::::::::::
56-
57-
:::::::::::::::: solution
44+
Open a terminal and install `uv` following the [official installation instructions](https://docs.astral.sh/uv/getting-started/installation/):
5845

59-
### Mac OS
46+
```sh
47+
curl -LsSf https://astral.sh/uv/install.sh | sh
48+
```
6049

61-
[Video tutorial][video-mac]
50+
Then make sure you are inside the `geospatial-python` directory you created during the data setup step. If not, please do:
6251

63-
1. Open [https://www.anaconda.com/download][anaconda-mac] with your web browser.
52+
```sh
53+
cd <path-to-geospatial-python>
54+
```
6455

65-
2. Download the Anaconda installer with Python 3 for OS X. These instructions assume that you use the "Graphical Installer" `.pkg` file
56+
Finally, run the following command to create a virtual environment and install the required dependencies:
6657

67-
3. Follow the Python 3 installation instructions. Make sure that the install location is set to **Install only for me** so Anaconda will install its files locally, relative to your home directory. Installing the software for all users tends to create problems in the long run and should be avoided.
58+
```sh
59+
uv venv --python=3.12 && uv pip install -r https://raw.githubusercontent.com/esciencecenter-digital-skills/geospatial-python/uv_setup/files/requirements.txt
60+
```
6861

6962
:::::::::::::::::::::::::
7063

7164

7265
:::::::::::::::: solution
7366

74-
### Linux
75-
76-
Note that the following installation steps require you to work from the shell.
77-
If you run into any difficulties, please request help before the workshop begins.
78-
79-
1. Open [https://www.anaconda.com/download][anaconda-linux] with your web browser.
80-
81-
2. Download the Anaconda installer with Python 3 for Linux.
67+
### Windows
8268

83-
3. Open a terminal window and navigate to the directory where the executable is downloaded (e.g., `cd ~/Downloads`).
69+
On Windows, first we install `uv` using PowerShell following the [official installation instructions](https://docs.astral.sh/uv/getting-started/installation/):
8470

85-
4. Type:
71+
```powershell
72+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
73+
```
8674

87-
```bash
88-
bash Anaconda3-
89-
```
75+
Sometimes after the installation, you may see suggestions powershell terminal like `$env:Path = "C:\Users\username\.local\bin;$env:Path"` This means you need to manually add the `uv` executable to your system's PATH variable. Please run the suggested command in your PowerShell terminal to add `uv` to your PATH. Otherswise PowerShell will not recognize the `uv` command in the next step.
9076

91-
and press "Tab" to autocomplete the full file name. The name of file you just downloaded should appear.
77+
Then make sure you are inside the `geospatial-python` directory you created during the data setup step. If not, please do:
9278

93-
5. Press "Enter" (or "Return" depending on your keyboard).
79+
```powershell
80+
cd <path-to-geospatial-python>
81+
```
9482

95-
6. Follow the text-only prompts. When the license agreement appears (a colon will be present at the bottom of the screen) press "Spacebar" until you see the bottom of the text. Type `yes` and press "Enter" to approve the license. Press "Enter" again to approve the default location for the files. Type `yes` and press "Enter" to prepend Anaconda to your `PATH` (this makes the Anaconda distribution your user's default Python).
83+
Finally, run the following command to create a virtual environment and install the required dependencies:
9684

97-
7. Close the terminal window.
85+
```powershell
86+
uv venv --python=3.12; if ($LASTEXITCODE -eq 0) { uv pip install -r https://raw.githubusercontent.com/esciencecenter-digital-skills/geospatial-python/uv_setup/files/requirements.txt}
87+
```
9888

9989
:::::::::::::::::::::::::
10090

91+
After the installation, a `.venv` directory will be created in the current directory, which contains the virtual environment with all the required dependencies.
10192

102-
### Setting up the workshop environment
103-
104-
If Anaconda was properly installed, you should have access to the `conda`
105-
command in your terminal (use the **Anaconda prompt** on **Windows**).
106-
107-
1. Test that `conda` is correctly installed by typing:
108-
109-
```bash
110-
conda --version
111-
```
93+
### Testing the installation
11294

113-
which should print the version of conda that is currently installed, e.g. :
95+
In order to follow the lesson, you should launch JupyterLab. Let's try it now to make sure everything is set up correctly. You can run the following command in your terminal from the `geospatial-python` directory:
11496

115-
```output
116-
conda 22.9.0
117-
```
118-
119-
2. Run the following command:
120-
121-
```bash
122-
conda install -c conda-forge mamba
123-
```
124-
125-
IMPORTANT: If your terminal responds to the above command with `conda: command not found` see the [Troubleshooting section](#troubleshooting-conda-command-not-found).
126-
127-
3. Create the Python environment for the workshop by running:
128-
129-
```bash
130-
mamba env create -n geospatial -f https://raw.githubusercontent.com/carpentries-incubator/geospatial-python/main/files/environment.yaml
131-
```
132-
133-
Note that this step can take several minutes.
134-
135-
4. When installation has finished you should see the following message in the terminal:
136-
137-
```output
138-
# To activate this environment, use
139-
# $ conda activate geospatial
140-
#
141-
# To deactivate an active environment, use
142-
# $ conda deactivate
143-
```
144-
145-
5. Now Activate the `geospatial` environment by running:
146-
147-
```bash
148-
conda activate geospatial
149-
```
150-
151-
If successful, the text `(base)` in your terminal prompt will now read
152-
`(geospatial)` indicating that you are now in the Anaconda virtual environment
153-
named `geospatial`. The command `which python` should confirm that we're using
154-
the Python installation in the `geospatial` virtual environment. For example:
155-
156-
```bash
157-
which python
158-
```
159-
160-
```output
161-
/Users/your-username/anaconda3/envs/geospatial/bin/python
16297
```
163-
164-
IMPORTANT: If you close the terminal, you will need to reactivate this
165-
environment with `conda activate geospatial` to use the Python libraries
166-
required for the lesson and to start JupyterLab, which is also installed in the
167-
`geospatial` environment.
168-
169-
### Starting JupyterLab
170-
171-
In order to follow the lesson, you should launch JupyterLab. After activating the
172-
geospatial conda environment, enter the following command in your terminal (use the **Anaconda prompt** on **Windows**):
173-
174-
```bash
175-
jupyter lab
98+
uv run jupyter lab
17699
```
177100

178101
Once you have launched JupyterLab, create a new Python 3 notebook, type the following code snippet in a cell and press the "Play" button:
@@ -183,42 +106,11 @@ import rioxarray
183106

184107
If all the steps above completed successfully you are ready to follow along with the lesson!
185108

186-
### Troubleshooting `conda: command not found`
187-
188-
* **Mac OS and Linux users:**
189-
190-
1. First, find out where Anaconda is installed.
191-
192-
The typical install location is in your `$HOME` directory (i.e., `/Users/your-username/`) so use `ls ~` to check whether an `anaconda3` directory is present in your home directory:
193-
194-
```bash
195-
ls ~
196-
```
197-
198-
```output
199-
Applications Downloads Pictures
200-
anaconda3 Library Public
201-
Desktop Movies
202-
Documents Music
203-
```
204-
205-
If, like above, you see a directory called `anaconda3` in the output we're in good shape. If not, **contact the instructor for help**.
206-
207-
2. Activate the `conda` command-line program by entering the following command:
208-
209-
```bash
210-
source ~/anaconda3/bin/activate
211-
```
212-
If all goes well, nothing will print to the terminal and your prompt will now have `(base)` floating around somewhere
213-
on the left. This is an indication that you are in the base Anaconda environment.
109+
::: callout
214110

215-
Continue from the beginning of step 3 to complete the creation of the `geospatial` virtual environment.
111+
### Alternative: software setup using Anaconda
216112

113+
If you prefer to use Anaconda, you can follow the alternative setup instructions on [this
114+
page](./setup_alternative.md).
217115

218-
[anaconda]: https://www.anaconda.com/
219-
[anaconda-mac]: https://www.anaconda.com/download/#macos
220-
[anaconda-linux]: https://www.anaconda.com/download/#linux
221-
[anaconda-windows]: https://www.anaconda.com/download/#windows
222-
[python]: https://python.org
223-
[video-mac]: https://www.youtube.com/watch?v=TcSAln46u9U
224-
[video-windows]: https://www.youtube.com/watch?v=xxQ0mzZ8UvA
116+
:::

0 commit comments

Comments
 (0)