Installing Python Packages
numpy, pandas, matplotlib and Pillow need no install: they load by themselves when you import them. For anything else, put !pip install and the package's name at the top of a Python file or a CodeBook cell, the way you would in a notebook:
!pip install plotly
import plotly.graph_objects as go
- The first run installs it. You'll see "Installing plotly…" while it downloads.
- Later runs skip it. The package is already there, so the line costs nothing and needs no internet.
- Several at once:
!pip install plotly rich sympy. - A version:
!pip install "plotly>=5". %pip installworks too. Options like-qand--upgradeare accepted and ignored.
The pip line is the only way to install a Python package in Circuitry. There is no package window or button to look for, and nothing is installed just because a file imports it: only a pip line you can see in your own code installs anything.
What a pip line looks like
Circuitry reads a line as a pip line when it starts with one of these. Spaces before it are fine, so it can sit inside an if or a function:
| Line starts with | Example |
|---|---|
!pip install | !pip install rich |
%pip install | %pip install rich |
!pip3 install | !pip3 install rich |
!python -m pip install | !python -m pip install rich |
- Only
installis read.!pip list,!pip uninstalland other!commands are not pip lines, and Python reports them as a syntax error. - Options are dropped, and an option's value goes with it. The one exception is
-r: Circuitry does not read a requirements file, so!pip install -r requirements.txtstops the run with a message saying so. Name the packages on the line instead:!pip install requests rich. - A
#comment after the names is ignored.
In a Pyctures scene
A Pyctures scene installs packages the same way. Put the pip line at the top of the file, and the preview installs the package before it starts drawing, showing "Installing …" while it does. The pyctures module itself is built in and needs no pip line.
!pip install colour
from colour import Color
shades = list(Color("blue").range_to(Color("gold"), 8))
def draw():
for i, shade in enumerate(shades):
ctx.fill_style = shade.hex_l
ctx.fill_rect(20 + i * 45, 20, 40, 120)
On iPhone and iPad, a scene that asks for a package with compiled parts draws on the page's Python instead of the built-in one. The preview says so once, then runs.
Where packages go
Python runs in different places, and Circuitry picks the place for you. Each keeps its own packages:
| Where Python runs | Where packages install |
|---|---|
| In the browser | The page's own Python, for as long as the page is open |
| On a computer with Circuit | A folder of Circuit's own. Your computer's Python is never changed |
| On iPhone and iPad | The app's own storage, kept between launches |
On iPhone and iPad
Circuitry's built-in Python on iPhone and iPad installs packages written purely in Python, such as plotly and rich. Some packages need compiled parts (pandas, scikit-learn, Altair), which only an app update can add. When a file asks for one of those, it runs on the page's Python instead, automatically. numpy, matplotlib and Pillow are already built in.
When it doesn't work
- "No package called … was found": check the spelling. The name is the one you would give pip on a computer, which is not always the name you import (
!pip install scikit-learn, thenimport sklearn). - No internet on the first run: the install needs a connection once. After that the package is there.
- A package with compiled parts, in the browser: the page's Python can install packages written purely in Python, and the compiled ones that were built for it (numpy, pandas, scipy and many more). For any other compiled package, the run stops with an error that names it and says no pure Python wheel was found. Run the file in the desktop app, where Circuit uses real pip.
- On a computer with Circuit, pip itself fails: the run stops with pip could not install … and pip's own last error line.
- Scheduled and webhook runs cannot install packages. Keep
!pip installto files and cells you run yourself.
Next
- Node Packages (npm): packages for JavaScript and React projects.
- Charts and Tables: show plotly, matplotlib, pandas and Altair output beside your code.
- Languages and where they run
- Coming from Jupyter