Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rhino scripts default install path is wrong for Rhino 8 #1351

Open
obucklin opened this issue May 2, 2024 · 6 comments
Open

Rhino scripts default install path is wrong for Rhino 8 #1351

obucklin opened this issue May 2, 2024 · 6 comments

Comments

@obucklin
Copy link

obucklin commented May 2, 2024

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!

@petrasvestartas
Copy link
Contributor

petrasvestartas commented May 2, 2024

I guess ScriptEditor usage for Rhino8 is still experimental as stated in the Compas documentation:
image

import compas_rhino.install

Python library installation directory and Grasshopper are two different directories.

What works for me is following:

Grasshopper for ScriptEditor Rhino8 CPython on Windows:
python src\rhino\gh\componentize_cpy.py src\rhino\gh\cpy %APPDATA%\Grasshopper\UserObjects

on mac
python src/rhino/gh/componentize_cpy.py src/rhino/gh/cpy "/Users/petras/Library/Application Support/McNeel/Rhinoceros/8.0/Plug-ins/Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)/UserObjects"

or the package manager directory (manual upload to Rhino).

The python libraries I install as described in compas main page:
https://compas.dev/compas/latest/userguide/cad.rhino8.html
When a library is ready, I do it via pip, since this is the only possible solution to link a library in script editor is via # r: keyword.
Conda environments will be supported "maybe" in the future. This whole thing is painful, but at least it is CPython not IronPython...

@gonzalocasas gonzalocasas changed the title componentizer default install path is wrong for Rhino 8 Rhino scripts default install path is wrong for Rhino 8 May 2, 2024
@ChiaChing-Yen
Copy link

@petrasvestartas I followed this thread and it suggests adding # env: /path/to/site-package to the script to enable using that environment in Rhino. After adding this line, there's no need to use # r: module.
I used conda to create an environment with the same Python version as Rhino 8, then installed compas and compas_fab packages. I tried importing the modules, and they worked successfully.
While I haven't investigated this further, it seems like a viable workaround to make conda work with Rhino 8.

@gonzalocasas
Copy link
Member

This is very good news! Thanks @ChiaChing-Yen !

@jf---
Copy link
Contributor

jf--- commented Aug 6, 2024

I've run into the same issue: compas explicitly installs in the ironpython folder (/.rhinocode/py27-rh8/Lib/site-packages vs /.rhinocode/py39-rh8/Lib/site-packages, over rhino3, which seems at odds with the herculean effort of the compas team working towards python3 compatibility.

    # In Rhino 8 there is no scripts folder
    if version == "8.0":
        installation_path = compas_rhino._get_default_rhino_ironpython_sitepackages_path(version)
    else:
        installation_path = compas_rhino._get_rhino_scripts_path(version)

So @obucklin suggestion makes perfect sense to install into the scripts directory, so just factoring out the if statement should resolve things:

In [6]: compas_rhino._get_rhino_scripts_path("8.0")
Out[6]: '/Users/jelle/Library/Application Support/McNeel/Rhinoceros/8.0/scripts'

In my view, this is a pressing issue, given that compas is getting increasing less / incompatible with ironpython and the considerable hinderance associated to running iron python (no numpy etc). To speak for myself: python3 compatibility was more then sufficient reason to move to rhino 8 ;)

@tomvanmele
Copy link
Member

not sure i understand what is being proposed.

the current installation mechanism is not wrong. in Rhino 8, COMPAS packages should indeed be installed in the site packages folder of the Python flavour and version you intend to use. there are two reasons for this.

  1. if the scripts folder is used we can't differentiate between IronPython and CPython installs. using the scripts folder can create really weird clashes between packages and package versions that are difficult to debug.
  2. specifically for CPython installs, pip can now be used to install packages directly from the Python Package Index. if we install packages in the scripts folder using symlinks as we did with older versions of Rhino, this installation mechanism no longer works properly.

if there are other problems with correct versions of packages not being found by other components of Rhino, i would prefer trying to solve those problems specifically. changing the installation mechanism is not the solution in my opinion...

@chenkasirer
Copy link
Member

Sorry, I'm late for the party.
I made #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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants