Skip to content

Commit 0b6b63b

Browse files
committed
uv everywhere
1 parent 863de04 commit 0b6b63b

File tree

5 files changed

+104
-47
lines changed

5 files changed

+104
-47
lines changed

docs/src/appendix/index.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22

33
While there are numerous ways to install and configure Python for data analysis, advanced users like to take advantage of modern Python tools to have more control over when and where code is installed on their system.
44

5-
This guide will demonstrate how to install everything your computer needs using either traditional tools like pipenv or modern alternatives like uv.llation
6-
7-
While there are numerous ways to install and configure Python for data analysis, advanced users like to take advantage of modern Python tools to have more control over when and where code is installed on their system.
8-
9-
This guide will demonstrate how to install everything your computer needs using either traditional tools like pipenv or modern alternatives like uv.
5+
This guide provides comprehensive setup instructions using [uv](https://docs.astral.sh/uv/), a fast and modern Python package manager that simplifies dependency management and virtual environments.
106

117
```{contents} Sections
128
:depth: 1
139
:local:
1410
```
1511

16-
## A command-line interface/_templates/nav.html
17-
```
18-
19-
# Advanced installation
20-
2112
While there are numerous ways to install and configure Jupyter notebooks, advanced users like to take advantage of Python’s power tools to have more control over when and where code is installed on their system.
2213

2314
This guide will demonstrate how to install everything your computer needs to play like the pros.
@@ -67,9 +58,11 @@ Instructions for both new installations and upgrades can be found [here](https:/
6758

6859
## Package and environment managers
6960

70-
Modern Python development benefits from using package managers that handle dependencies and virtual environments automatically. We'll cover two popular options: uv (recommended for new projects) and pipenv (traditional approach).
61+
## Python Package Management with uv
62+
63+
Modern Python development benefits from using package managers that handle dependencies and virtual environments automatically. We recommend [uv](https://docs.astral.sh/uv/) for all users because it's fast, reliable, and simple to use.
7164

72-
### Option 1: uv (Recommended)
65+
### Installing uv
7366

7467
[uv](https://docs.astral.sh/uv/) is a modern, fast Python package manager written in Rust that makes dependency management simple and reliable. It automatically handles virtual environments and is significantly faster than traditional tools.
7568

docs/src/notebooks/export.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
" final_analysis.to_excel(\"helicopter_accident_rates.xlsx\", index=False, sheet_name=\"Accident Rates\")\n",
105105
" print(\"Exported to Excel: helicopter_accident_rates.xlsx\")\n",
106106
"except ImportError:\n",
107-
" print(\"Excel export requires openpyxl. Install with: pip install openpyxl\")"
107+
" print(\"Excel export requires openpyxl. Install with: uv add openpyxl\")"
108108
]
109109
},
110110
{
@@ -140,7 +140,7 @@
140140
" \n",
141141
" print(\"Exported multi-sheet Excel file: helicopter_analysis_complete.xlsx\")\n",
142142
"except ImportError:\n",
143-
" print(\"Excel export requires openpyxl. Install with: pip install openpyxl\")"
143+
" print(\"Excel export requires openpyxl. Install with: uv add openpyxl\")"
144144
]
145145
},
146146
{

docs/src/notebooks/pandas.ipynb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"```{note}\n",
4545
"Since pandas is created by a third party independent from the core Python developers, it wouldn't be installed by default in a basic Python installation.\n",
4646
"\n",
47-
"If you followed the VS Code setup chapter and used uv to set up your project, pandas should already be installed. If your Python environment doesn't have pandas, you can install it by opening the VS Code terminal (`View > Terminal`) and running `uv add pandas` (if using uv) or `pip install pandas` (if using pip).\n",
47+
" \"If you followed the VS Code setup chapter and used uv to set up your project, pandas should already be installed. If your Python environment doesn't have pandas, you can install it by opening the VS Code terminal (`View > Terminal`) and running `uv add pandas`.\\n\",\n",
4848
"```\n",
4949
"\n",
5050
"Return to your import section and rewrite it like this:"
@@ -55,7 +55,18 @@
5555
"execution_count": null,
5656
"id": "8fa1655e",
5757
"metadata": {},
58-
"outputs": [],
58+
"outputs": [
59+
{
60+
"ename": "",
61+
"evalue": "",
62+
"output_type": "error",
63+
"traceback": [
64+
"\u001b[1;31mRunning cells with 'first-python-notebook-vscode (Python 3.12.7)' requires the ipykernel package.\n",
65+
"\u001b[1;31mInstall 'ipykernel' into the Python environment. \n",
66+
"\u001b[1;31mCommand: '/Users/dwillis/code/first-python-notebook-vscode/.venv/bin/python -m pip install ipykernel -U --force-reinstall'"
67+
]
68+
}
69+
],
5970
"source": [
6071
"import pandas as pd"
6172
]
@@ -158,8 +169,14 @@
158169
}
159170
],
160171
"metadata": {
172+
"kernelspec": {
173+
"display_name": "first-python-notebook-vscode",
174+
"language": "python",
175+
"name": "python3"
176+
},
161177
"language_info": {
162-
"name": "python"
178+
"name": "python",
179+
"version": "3.12.7"
163180
}
164181
},
165182
"nbformat": 4,

docs/src/pandas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If nothing happens, that's good. It means you have pandas installed and ready to
4343
```{note}
4444
Since pandas is created by a third party independent from the core Python developers, it wouldn't be installed by default in a basic Python installation.
4545
46-
If you followed the VS Code setup chapter and used uv to set up your project, pandas should already be installed. If your Python environment doesn't have pandas, you can install it by opening the VS Code terminal (`View > Terminal`) and running `uv add pandas` (if using uv) or `pip install pandas` (if using pip).
46+
If you followed the VS Code setup chapter and used uv to set up your project, pandas should already be installed. If your Python environment doesn't have pandas, you can install it by opening the VS Code terminal (`View > Terminal`) and running `uv add pandas`.
4747
```
4848

4949
Return to your import section and rewrite it like this:

docs/src/vscode_setup.md

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Examples of data journalism projects that could be developed using VS Code inclu
1616

1717
You can find thousands of Python projects on [GitHub](https://github.com/search?q=language%3APython+data+analysis&type=Repositories) that use VS Code for development, including projects by [The New York Times](https://github.com/nytimes), [FiveThirtyEight](https://github.com/fivethirtyeight), [BuzzFeed News](https://github.com/BuzzFeedNews), and many others.
1818

19-
There are several ways to set up Python development in VS Code. Since this tutorial is designed for beginners, we'll show you how to install VS Code and set up a Python environment that includes all the tools you need for data analysis.
19+
There are several ways to set up Python development in VS Code. This tutorial uses [uv](https://docs.astral.sh/uv/), a fast and modern Python package manager that makes dependency management simple and reliable. We'll walk you through installing VS Code, Python, uv, and all the tools you need for data analysis.
2020

2121
```{note}
22-
Advanced users who prefer command-line tools can still follow this tutorial, but may want to use their existing Python environments. The code examples will work in any Python environment with pandas and other data analysis libraries installed.
22+
We recommend uv for all users because it automatically manages Python installations and virtual environments, preventing common setup issues. Advanced users familiar with other tools (conda, pipenv, etc.) can adapt the examples, but following the uv approach will give you the smoothest experience.
2323
```
2424

2525
## Install Visual Studio Code
@@ -77,42 +77,94 @@ This extension enables:
7777
- Data viewer for pandas DataFrames
7878
- Notebook diffing and merge capabilities
7979

80-
## Set Up Python Environment
80+
## Install uv (Python Package Manager)
81+
82+
Before setting up Python, we'll install uv, which will handle Python installation and package management for us. This approach ensures you get the latest Python version and eliminates common environment issues.
83+
84+
Open your terminal or command prompt and run the appropriate command for your operating system:
85+
86+
**On macOS and Linux:**
87+
```bash
88+
curl -LsSf https://astral.sh/uv/install.sh | sh
89+
```
90+
91+
**On Windows:**
92+
```bash
93+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
94+
```
8195

82-
VS Code works with any Python installation on your system. If you don't have Python installed:
96+
After installation, restart your terminal or command prompt to ensure uv is available.
97+
98+
**Verify installation:**
99+
```bash
100+
uv --version
101+
```
83102

84-
### For Beginners: Python from python.org
103+
You should see the uv version number, confirming it's installed correctly.
85104

86-
1. Visit [python.org](https://www.python.org/downloads/)
87-
2. Download Python 3.8 or newer
88-
3. Run the installer and make sure to check "Add Python to PATH"
105+
## Set Up Your Project with uv
89106

90-
### For Advanced Users: Anaconda, Miniconda, or uv
107+
Now we'll create a new Python project and install all required packages. uv will automatically download and set up the correct Python version for you.
91108

92-
If you're familiar with Python environments, you can use:
93-
- [uv](https://docs.astral.sh/uv/) (recommended - fast and modern Python package manager)
94-
- [Anaconda](https://www.anaconda.com/products/distribution) (includes many data science packages)
95-
- [Miniconda](https://docs.conda.io/en/latest/miniconda.html) (minimal installer)
96-
- [pyenv](https://github.com/pyenv/pyenv) for managing multiple Python versions
109+
1. **Create your project directory:**
110+
```bash
111+
uv init first-python-notebook
112+
cd first-python-notebook
113+
```
114+
115+
2. **Install required packages:**
116+
```bash
117+
uv add pandas matplotlib seaborn jupyter altair
118+
```
119+
120+
This command will:
121+
- Download and install Python 3.12+ if needed
122+
- Create a virtual environment automatically
123+
- Install all required packages for data analysis
124+
- Create a `pyproject.toml` file to track dependencies
125+
126+
The installation may take a few minutes the first time as uv downloads Python and packages.
127+
128+
## Set Up Python Environment
129+
130+
Now we'll install uv, which will handle both Python installation and package management for us.
131+
132+
## Install uv
133+
134+
uv is a fast Python package manager that automatically handles Python installation and virtual environments. It's the simplest way to get everything set up correctly.
97135

98136
## Verify Your Setup
99137

100-
Let's verify everything is working:
138+
Let's verify everything is working by testing Python and our installed packages:
101139

102-
1. Open VS Code
103-
2. Create a new file by pressing `Ctrl+N` (or `Cmd+N` on Mac)
104-
3. Save it as `test.py` (press `Ctrl+S` or `Cmd+S`)
105-
4. Type the following code:
140+
1. **Open VS Code in your project:**
141+
```bash
142+
code .
143+
```
144+
145+
2. **Create a test file:** Press `Ctrl+N` (or `Cmd+N` on Mac) to create a new file
146+
3. **Save it as `test.py`:** Press `Ctrl+S` (or `Cmd+S`) and name it `test.py`
147+
4. **Add test code:**
106148

107149
```python
108-
print("Hello, VS Code!")
150+
import pandas as pd
151+
import matplotlib.pyplot as plt
152+
import seaborn as sns
153+
import altair as alt
154+
155+
print("🎉 All packages imported successfully!")
156+
print(f"Python version: {pd.np.version.version}")
157+
print(f"pandas version: {pd.__version__}")
158+
print(f"altair version: {alt.__version__}")
109159
```
110160

111-
5. Right-click in the editor and select "Run Python File in Terminal"
161+
5. **Run the file:** Right-click in the editor and select "Run Python File in Terminal"
112162

113-
You should see "Hello, VS Code!" printed in the integrated terminal at the bottom of the screen.
163+
You should see success messages and version numbers printed in the integrated terminal at the bottom of the screen.
114164

115-
![First Python program](/_static/vscode-hello-world.png)
165+
```{tip}
166+
If you see import errors, make sure VS Code has selected the correct Python interpreter (see the next section on environment selection).
167+
```
116168

117169
## Install Required Packages
118170

@@ -130,11 +182,6 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
130182
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
131183
```
132184

133-
**Alternative installation via pip:**
134-
```bash
135-
pip install uv
136-
```
137-
138185
Once uv is installed, create a new Python project and install the required packages:
139186

140187
```bash
@@ -159,7 +206,7 @@ uv is much faster than pip and provides better dependency resolution. It automat
159206

160207
## Your First Interactive Session
161208

162-
VS Code supports multiple ways to work with Python and Jupyter notebooks. If you set up your project with uv, make sure you're working in the project directory:
209+
VS Code provides excellent support for working with Python and Jupyter notebooks. Now that you've set up your project with uv, make sure you're working in the project directory:
163210

164211
```bash
165212
cd first-python-notebook

0 commit comments

Comments
 (0)