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:
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)
Agree. to sum up and make actionable I propose the following (I can make the changes)
compas_invocations2add ability to distinguish between component source for ironpython and cpython (as these will most likely need to co-exist)compas-actions.ghpython_componentsadd theyakerize.pyscript (thanks @9and3!) to the componentizer and expose it via the github actioncompas_invocations2addyakerizeinvoke command to allow local packagingcompas- remove the8.0flag fromcompas_rhino.installcompas- add cpython compatible copy of the components tocompas_ghpython\components_cpythoncompas-actions.build/publish- extend to build yak packages for rhino7 and rhino8when using YAK, components are installed to
AppData\Roaming\McNeel\Rhinoceros\packages\7.0and...\8.0the Rhino8 components need to have#r: compasat the top which will take care of the python dependencies.Rhino7 components would need the good old
compas_rhino.install -v7.0to 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, ....Different combinations of requirements for different projects can be isolated from each other using
# venv: ....More advanced users may want to/need to use
pipdirectly themselves instead of using# r: .... There are two options:pippipof a external (conda) environment with the correct--target.the target directive can also be combined with the usage of Rhino’s
pipto install packages into specificvenv. not however, that Rhino adds a random string to the names of the virtual environments insite-envs(don’t know why) and that you need to know what this string is in order to use--targetproperly.Rhino pip
Install
compasinto the default site-env using Rhino’spip, directly from PyPI:Install
compasinto a specific site-env (“projectA”) using Rhino’spip, directly from PyPI: (The random string i used (“projectA-htl4ZgZ0”) will be different for everyone, and needs to be looked up first.)The same can be done with source installs into the default or a specific site-env:
NOT Rhino pip
Instead of using Rhino’s
pip, you can also use thepipof 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--targetis not optional, even for the default site-env.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 likecompas_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.
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):
Oldlabel)And the corresponding locations are:
McNeel/Rhinoceros/8.0/scriptspy27-rh8/Lib/site-packagespy39-rh8/lib/site-packagesI do agree we should utilize the
pipmechanism that’s now made possible but I had some weird issue happening when I tried it out withcompas_rhino.install_with_pipplus I think it should eventually be integrated into thecompas_rhino.install.Another related issue I’m having is I cannot for the life of me import
compas_ghpythonin a python3 components. It doesn’t matter if I install via pip or with symlinks. Just getting this persistentNotSupportedInGHException. 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?