Can you install a CPython package from a different index in Rhino 8?

I’m trying to make a plugin that utilizes a CPython package, and I’m trying to find the best way to distribute the package to users of the plugin. The plugin itself won’t be available outside of my lab, and we can’t put the package up on PyPI, but we do have an internal package index. Normally, we could use something like pip install --index-url https://my.package.index/ mypackage, but this doesn’t seem to be possible within the new Script Editor in Rhino 8. Is there any way to specify a package index, or am I locked into PyPI? In a similar vein, is it possible to install local packages (downloaded as a wheel or tarball)?

After poking around a little bit, it seems that Rhino searches for any line of text that looks like # r: mypackage and then tries to install mypackage. Doing something like # r: --index-url https://my.package.index/ mypackage bricks the script because it tries to create a folder with the name --index-url https://my.package.index/ mypackage. Putting the --index-url bit in an earlier comment also doesn’t work because it once again tries to make an invalid folder. It clearly isn’t passing the string following # r: into pip install, and it isn’t treating all of the requirements comments as lines in a requirements file.

I know how to distribute the package within the yak file, but it would be nice to not have other people in the lab reinstall the plugin every time I update the package.

I’ve found a way to hack it together by first installing a package from PyPI like numpy and then manually running the pip install via a subprocess call.

#! python3
# r: numpy

import sys
import pathlib
import numpy
import subprocess

lib_to_install = "..."

executable_path = pathlib.Path(sys.prefix) / "python.exe"
env_path = pathlib.Path(numpy.__file__).parents[1]
call_args = [executable_path, "-m", "pip", "install", lib_to_install, f"--target={env_path}"]

import mypackage

Does anyone know a better way to do this?

@Russell_Newton I have a ticket here to implement other package sources. I’ll get to this soon after I have cleared most of current bugs :smiley:

RH-75515 Allow using custom package sources


Hey @eirannejad , just wondering – will it be ready soon? I’m about to put the core part of my project (Euglena) on PyPI, but it’s more than 100 MB because of the TensorFlow stuff.
Last time, I made a simple setup in Python. I’d like to upload the package to github and install it with pip. Also, it’d be nice if the script component showed when it’s downloading packages. There’s a lot of waiting when it installs something big like MediaPipe, so users may think it’s frozen.

1 Like

… upload the package to github and install it with pip…

You mean using the pip install git+ pattern to install directly from a git repo?

The editor originaly showed a green bar notifying that it is installing packages. The problem was that the Rhino UI would remain active and use could modify things before script was run. I’ll implement something similar soon:

RH-79324 Script Editor to notify when installing packages but make it block the UI

1 Like

Yes, maybe something like this could work

# r: mediapipe @git+

I forgot to mention I’m talking about Grasshopper’s script. Rhino script editor’s package installation sounds good to me.

1 Like

Ok. I’m going to support urls supported by pip in the format:

# r: <vcs project url>

Note that the package name is not necessary since the target is pointing to the one package. This acts like:

pip install <vcs project url>

1 Like