Skip to content

Commit 831cf03

Browse files
authored
consolidate venv docs (#1468)
1 parent f45cf92 commit 831cf03

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

docs/loaders.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,20 @@ For example, for the file `quakes.csv`, the following data loaders are considere
161161
162162
To use an interpreted data loader (anything other than `.exe`), the corresponding interpreter must be installed and available on your `$PATH`. Any additional modules, packages, libraries, _etc._, must also be installed. Some interpreters are not available on all platforms; for example `sh` is only available on Unix-like systems.
163163
164-
<div class="tip">
164+
<div class="tip" id="venv">
165165
166-
You can use a virtual environment in Python, such as [uv](https://github.com/astral-sh/uv), to install libraries locally to the project. This is useful when working in multiple projects, and when collaborating; you can also track dependencies in a `requirements.txt` file. To create a virtual environment with uv, run:
166+
You can use a virtual environment in Python, such as [venv](https://docs.python.org/3/tutorial/venv.html) or [uv](https://github.com/astral-sh/uv), to install libraries locally to the project. This is useful when working in multiple projects, and when collaborating; you can also track dependencies in a `requirements.txt` file.
167+
168+
To create a virtual environment with venv:
169+
170+
```sh
171+
python3 -m venv .venv
172+
```
173+
174+
Or with uv:
167175
168176
```sh
169-
uv venv # Create a virtual environment at .venv.
177+
uv venv
170178
```
171179
172180
To activate the virtual environment on macOS or Linux:
@@ -181,7 +189,7 @@ Or on Windows:
181189
.venv\Scripts\activate
182190
```
183191
184-
You can then run the `observable preview` or `observable build` commands as usual; data loaders will run within the virtual environment. Run the `deactivate` command to exit the virtual environment.
192+
You can then run the `observable preview` or `observable build` (or `npm run dev` or `npm run build`) commands as usual; data loaders will run within the virtual environment. Run the `deactivate` command or use Control-D to exit the virtual environment.
185193
186194
</div>
187195

examples/loader-python-to-csv/src/index.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,15 @@ results.to_csv(sys.stdout)
2828

2929
<div class="note">
3030

31-
To run this data loader, you’ll need python3 and the geopandas, matplotlib, io, and sys modules installed and available on your `$PATH`. We recommend setting up a virtual environment.
31+
To run this data loader, you’ll need python3 and the geopandas, matplotlib, io, and sys modules installed and available on your `$PATH`.
3232

3333
</div>
3434

35-
To start and activate a virtual Python environment, run the following commands:
35+
<div class="tip">
3636

37-
```
38-
$ python3 -m venv .venv
39-
$ source .venv/bin/activate
40-
```
41-
42-
Then install the required modules from `requirements.txt` using:
37+
We recommend using a [Python virtual environment](https://observablehq.com/framework/loaders#venv), such as with venv or uv, and managing required packages via `requirements.txt` rather than installing them globally.
4338

44-
```
45-
$ pip install -r requirements.txt
46-
```
39+
</div>
4740

4841
The above data loader lives in `data/predictions.csv.py`, so we can load the data using `data/predictions.csv` with `FileAttachment`:
4942

examples/loader-python-to-png/src/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ sys.stdout.buffer.write(img_buffer.getvalue())
2626

2727
<div class="note">
2828

29-
To run this data loader, you’ll need python3 and the geopandas, matplotlib, io, and sys modules installed and available on your `$PATH`. We recommend setting up a virtual environment, _e.g._ with:
29+
To run this data loader, you’ll need python3 and the geopandas, matplotlib, io, and sys modules installed and available on your `$PATH`.
3030

31-
- `$ python3 -m venv .venv`
32-
- `$ source .venv/bin/activate`
31+
</div>
3332

34-
Then install the required modules:
33+
<div class="tip">
3534

36-
- `$ pip install -r requirements.txt`
35+
We recommend using a [Python virtual environment](https://observablehq.com/framework/loaders#venv), such as with venv or uv, and managing required packages via `requirements.txt` rather than installing them globally.
3736

3837
</div>
3938

examples/loader-python-to-zip/src/data/earthquakes.zip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
# Write JSON string to the zip file
3333
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
34-
zip_file.writestr("quakes_metadata.json", earthquake_meta_json)
34+
zip_file.writestr("quakes-metadata.json", earthquake_meta_json)
3535

3636
# Write DataFrame to a CSV file in the zip file
3737
with zipfile.ZipFile(zip_buffer, "a") as zip_file:

examples/loader-python-to-zip/src/index.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ zip_buffer = io.BytesIO()
3636

3737
# Write JSON string to the zip file
3838
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
39-
zip_file.writestr("quakes_metadata.json", earthquake_meta_json)
39+
zip_file.writestr("quakes-metadata.json", earthquake_meta_json)
4040

4141
# Write DataFrame to a CSV file in the zip file
4242
with zipfile.ZipFile(zip_buffer, "a") as zip_file:
@@ -49,45 +49,40 @@ sys.stdout.buffer.write(zip_buffer.getvalue())
4949

5050
<div class="note">
5151

52-
To run this data loader, you’ll need python3, and the requests and pandas modules, installed and available on your `$PATH` (json, zipfile, io, and sys are part of the python3 standard library). We recommend setting up a virtual environment, for example using:
52+
To run this data loader, you’ll need python3, and the requests and pandas modules, installed and available on your `$PATH`. (json, zipfile, io, and sys are part of the python3 standard library.)
5353

54-
- `$ python3 -m venv .venv`
55-
- `$ source .venv/bin/activate`
54+
</div>
5655

57-
Install the requests and pandas modules (included in requirements.txt):
56+
<div class="tip">
5857

59-
- `$ pip install -r requirements.txt`
58+
We recommend using a [Python virtual environment](https://observablehq.com/framework/loaders#venv), such as with venv or uv, and managing required packages via `requirements.txt` rather than installing them globally.
6059

6160
</div>
6261

63-
The above data loader lives in `data/earthquakes.zip.py`. You can load the entire ZIP archive in a markdown page using FileAttachment:
62+
The above data loader lives in `data/earthquakes.zip.py`. You can load the entire ZIP archive in a markdown page using `FileAttachment`:
6463

6564
```js echo
66-
const quakeZip = FileAttachment("data/earthquakes.zip").zip()
65+
const earthquakes = FileAttachment("data/earthquakes.zip").zip();
6766
```
6867

69-
Or access individual files (`quakes_metadata.json` and `quakes.csv`) directly:
68+
Or access individual files (`quakes-metadata.json` and `quakes.csv`) directly:
7069

7170
```js echo
72-
const quakeMetadata = FileAttachment("data/earthquakes/quakes_metadata.json").json()
71+
const quakesMetadata = FileAttachment("data/earthquakes/quakes-metadata.json").json();
7372
```
7473

7574
```js echo
76-
const quakeData = FileAttachment("data/earthquakes/quakes.csv").csv({typed: true})
75+
const quakes = FileAttachment("data/earthquakes/quakes.csv").csv({typed: true});
7776
```
7877

79-
Take a quick look at the quakes data using Inputs.table:
78+
Take a quick look at the quakes data using `Inputs.table`:
8079

8180
```js echo
82-
Inputs.table(quakeData)
81+
Inputs.table(quakes)
8382
```
8483

8584
Then explore the distribution of earthquake magnitudes using Observable Plot:
8685

8786
```js echo
88-
Plot.plot({
89-
marks: [
90-
Plot.rectY(quakeData, Plot.binX({y: "count"}, {x: "mag", interval: 0.5}))
91-
]
92-
})
87+
Plot.rectY(quakes, Plot.binX({y: "count"}, {x: "mag"})).plot()
9388
```

0 commit comments

Comments
 (0)