Package References
A package reference is a line in your script that says which packages the script needs. The script carries its own list, so it installs what it needs when someone else opens it.
References come in two forms:
# short form, python 3 packages
#r: numpy
# full form, any package provider
#r "pip: numpy"
Use # to start the line in Python. In C# use #r or // r.
Python 3 Packages
#r: and #requirements: are the same thing, and take one or more packages:
#r: numpy
#requirements: numpy, requests
Versions are written the way pip writes them:
#r: torch==2.4.1
#r: numpy>=1.2
The full form does the same through the pip provider. Quote specs that contain spaces:
#r "pip: numpy"
#r "pip: requests[security]"
Your Own Libraries
A library of your own that is not published on PyPI can be installed in place, straight from the folder you develop it in:
#r "pip: --editable /Users/me/dev/mylibrary"
This is better than copying the library next to your script, which hides any properly installed copy of it.
Git Repositories
Packages can come from a repository, optionally pinned to a commit, tag, or branch:
#r "pip: git+https://github.com/user/repo.git"
#r "pip: git+https://github.com/user/repo.git@9e3c1a2"
Other Package Indexes
pip options are accepted alongside the packages, so a package can come from somewhere other than PyPI:
--index-url |
Use this index instead of PyPI |
--extra-index-url |
Also look in this index |
--find-links |
Look for packages at this path or url |
--no-index |
Do not use an index at all |
#r "pip: mypackage --index-url https://my.company.server/simple"
#r "pip: mypackage --no-index --find-links /Users/me/wheels"
Inline Script Metadata
Packages can also be declared in a PEP 723 block, which other Python tools read as well:
# /// script
# dependencies = ["numpy", "requests"]
# ///
import numpy as np
Only the dependencies list is read. Other fields in the block are ignored.
NuGet Packages
.NET packages are referenced with the nuget provider, from both C# and Python:
#r "nuget: RestSharp, 110.2.0"
#r "nuget: Newtonsoft.Json, 13.0.3"
Rhino Packages
Packages from the Rhino package server are referenced with the yak provider:
#r "yak: LunchBox, 2025.5.5"
Assembly Files
An assembly is referenced by name when it is already loaded in Rhino, or by path:
#r "System.Text.Json.dll"
#r "/path/to/my/assemblies/MySharedAssembly.dll"
Python 2 Packages
Python 2 has no pip. Wheel files are the only packages it installs, so a package has to be a .whl file on disk:
#wheel: /path/to/package.whl
The full form does the same:
#r "wheel: /path/to/package.whl"
Related Topics
- Python Package Environments for keeping packages of one script away from another with
# venv: - Python Path Files for adding module search paths
- Scripting: Python
- Scripting: C#
