mirror of
https://github.com/jbranchaud/til
synced 2026-08-31 16:51:46 +00:00
Add Start Jupyter Notebook With Extra Packages as a Python TIL
This commit is contained in:
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
|
||||||
|
|
||||||
_1841 TILs and counting..._
|
_1842 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
|
|
||||||
@@ -1112,6 +1112,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
|||||||
- [Skip Specific Pytest Test Cases](python/skip-specific-pytest-test-cases.md)
|
- [Skip Specific Pytest Test Cases](python/skip-specific-pytest-test-cases.md)
|
||||||
- [Sort A List Of Dataclass Instances](python/sort-a-list-of-dataclass-instances.md)
|
- [Sort A List Of Dataclass Instances](python/sort-a-list-of-dataclass-instances.md)
|
||||||
- [Sort Normalized Version Of Data](python/sort-normalized-version-of-data.md)
|
- [Sort Normalized Version Of Data](python/sort-normalized-version-of-data.md)
|
||||||
|
- [Start Jupyter Notebook With Extra Packages](python/start-jupyter-notebook-with-extra-packages.md)
|
||||||
- [Start The Debugger When A Test Errors](python/start-the-debugger-when-a-test-errors.md)
|
- [Start The Debugger When A Test Errors](python/start-the-debugger-when-a-test-errors.md)
|
||||||
- [Store And Access Immutable Data In A Tuple](python/store-and-access-immutable-data-in-a-tuple.md)
|
- [Store And Access Immutable Data In A Tuple](python/store-and-access-immutable-data-in-a-tuple.md)
|
||||||
- [Strictly Separate Positional And Keyword Arguments](python/strictly-separate-positional-and-keyword-arguments.md)
|
- [Strictly Separate Positional And Keyword Arguments](python/strictly-separate-positional-and-keyword-arguments.md)
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Start Jupyter Notebook With Extra Packages
|
||||||
|
|
||||||
|
I can start up a one-off [Jupyter notebook](https://jupyter.org/) with
|
||||||
|
[`uv`](https://docs.astral.sh/uv/) with the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ uv run --with jupyter jupyter lab
|
||||||
|
```
|
||||||
|
|
||||||
|
The `--with` flag is a `uv run` feature for [requesting additional
|
||||||
|
dependencies](https://docs.astral.sh/uv/concepts/projects/run/#requesting-additional-dependencies).
|
||||||
|
In this case, it includes the `jupyter` package as a dependency which is
|
||||||
|
necessary for the command to then run `jupyter lab`.
|
||||||
|
|
||||||
|
As I started following along with [Andrej Karpathy's "Neural Networks: Zero to
|
||||||
|
Hero" series](https://karpathy.ai/zero-to-hero.html), I quickly ran into an
|
||||||
|
issue with missing other dependencies. In the opening video, Andrej is importing
|
||||||
|
`numpy` and `matplotlib`. To ensure those packages are also available for import
|
||||||
|
in this notebook, I need to `--with` them as well.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ uv run --with jupyter --with numpy --with matplotlib jupyter lab
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, when I execute the following step, I don't have any import issues:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import math
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
%matplotlib inline
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user