compas: Rhino scripts default install path is wrong for Rhino 8

python -m compas_rhino.install adds the COMPAS packages to ~/.rhinocode/py27-rh8/Lib/site-packages instead of \AppData\Roaming\McNeel\Rhinoceros\8.0\scripts. Grasshopper components cannot then import the modules.

there is a workaround which is to include

pt = r"C:\Users\obucklin/.rhinocode/py27-rh8/Lib/site-packages"

if pt not in sys.path:
    sys.path.append(pt)

at the top of a python component. This fixes IronPython components.

I’m not sure if it’s the same problem, but cpython components built with invoke build-cpython-ghuser-components do not instantiate on the canvas and result in a User Object failed to deserialize error:

image

Windows 11 Rhino 8 SR6 2024-4-10 COMPAS 2.1.0

Thanks!

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 17 (15 by maintainers)

Most upvoted comments

Agree. to sum up and make actionable I propose the following (I can make the changes)

  • compas_invocations2 add ability to distinguish between component source for ironpython and cpython (as these will most likely need to co-exist)
  • compas-actions.ghpython_components add the yakerize.py script (thanks @9and3!) to the componentizer and expose it via the github action
  • compas_invocations2 add yakerize invoke command to allow local packaging
  • compas - remove the 8.0 flag from compas_rhino.install
  • compas - add cpython compatible copy of the components to compas_ghpython\components_cpython
  • compas-actions.build/publish - extend to build yak packages for rhino7 and rhino8

when using YAK, components are installed to AppData\Roaming\McNeel\Rhinoceros\packages\7.0 and ...\8.0 the Rhino8 components need to have #r: compas at the top which will take care of the python dependencies.

Rhino7 components would need the good old compas_rhino.install -v7.0 to have their dependencies available (AKA symlinks in \AppData\Roaming\McNeel\Rhinoceros\7.0\scripts)

not sure if they are helpful, but here are a few thoughts…

Rhino CPython (py39)

Basic users should use the default installation mechanism provided by Rhino, using # r: compas, ....

#! python3
# r: compas, ...

Different combinations of requirements for different projects can be isolated from each other using # venv: ....

#! python3
# venv: projectA
# r: compas, ...

More advanced users may want to/need to use pip directly themselves instead of using # r: .... There are two options:

  • use Rhino’s pip
  • use the pip of a external (conda) environment with the correct --target.

the target directive can also be combined with the usage of Rhino’s pip to install packages into specific venv. not however, that Rhino adds a random string to the names of the virtual environments in site-envs (don’t know why) and that you need to know what this string is in order to use --target properly.

Rhino pip

Install compas into the default site-env using Rhino’s pip, directly from PyPI:

~/.rhinocode/py39-rh8/python3.9 -m pip install compas

Install compas into a specific site-env (“projectA”) using Rhino’s pip, directly from PyPI: (The random string i used (“projectA-htl4ZgZ0”) will be different for everyone, and needs to be looked up first.)

~/.rhinocode/py39-rh8/python3.9 -m pip install compas --target ~/.rhinocode/py39-rh8/site-envs/projectA-htl4ZgZ0

The same can be done with source installs into the default or a specific site-env:

cd path/to/compas
~/.rhinocode/py39-rh8/python3.9 -m pip install .
cd path/to/compas
~/.rhinocode/py39-rh8/python3.9 -m pip install . --target ~/.rhinocode/py39-rh8/site-envs/projectA-htl4ZgZ0

NOT Rhino pip

Instead of using Rhino’s pip, you can also use the pip of an external environment you might be working in (ideally this environment is based on Python 3.9, but depending on the requirements of the packages you install this is not always absolutely necessary). however, in this case --target is not optional, even for the default site-env.

conda activate compas-dev
cd path/to/compas
python -m pip install . --target ~/.rhinocode/py39-rh8/site-envs/projectA-htl4ZgZ0

Using an external environment directly as suggested above (using # env: path/to/site-packages) is not something i have been able to get to work, but i have only tried it on Mac. In any case, i doubt it will work for packages that are built and have build requirements like compas_cgal.

Rhino IronPython

the “py27-rh8” folder has a very similar structure as the one of “py39-rh8” so i assume that at least the installation procedures listed above that use local source will work as well, but i haven’t tried this…

GH

About Grasshopper i have no idea, but i can confirm that Python 3 components have access to the same “site-envs” as the Rhino ScriptEditor.

Screenshot 2024-11-15 at 14 24 55

Sorry, I’m late for the party. I made https://github.com/compas-dev/compas/pull/1384 and only then saw this thread after…

@tomvanmele could you please elaborate on point 1.? I don’t quite get it.

I find installing compas to 3 places is necessary in Rhino8 as there seems to be 3 different interpreters (or 2 in 3 environments):

  • Legacy IronPython (Old label)
  • IronPython (this is both new GH IronPython components and the EditPythonCode diaglog in Rhino)
  • CPython

And the corresponding locations are:

  • McNeel/Rhinoceros/8.0/scripts
  • py27-rh8/Lib/site-packages
  • py39-rh8/lib/site-packages

I do agree we should utilize the pip mechanism that’s now made possible but I had some weird issue happening when I tried it out with compas_rhino.install_with_pip plus I think it should eventually be integrated into the compas_rhino.install.

Another related issue I’m having is I cannot for the life of me import compas_ghpython in a python3 components. It doesn’t matter if I install via pip or with symlinks. Just getting this persistent NotSupportedInGHException. It seems to be for some call related to layers but even removing all those I could find didn’t get me anywhere.

Any of you stumbled upon that or had better luck?