Rhino Python Editor: No module named Grasshopper

Hi all,

My Rhino Python Editor can no longer import the Grasshopper module.

I wrote a little script (script A) that opens grasshopper files from Python.

import rhinoscriptsyntax as rs
import Grasshopper as gh
import os

docName = rs.DocumentName()
docPath = rs.DocumentPath()

ghPath = docPath + docName[:docName.rfind(".")] + ".gh"

if os.path.exists(ghPath):
    print "Opening associated GH file ", ghPath
    gh_scriptinterface = gh.Plugin.GH_RhinoScriptInterface()

It was working just fine until, I tried to run script A from a subprocess while opening a 3DM file, something like the below (script B)

callScript = '"{0}" "{2}" /nosplash /runscript="{1}"'.format(rhinoPath, scriptCall, fileName)

Now my Rhino python editor cannot import Grasshopper at all. I get the following error message:


I restarted my computer and the issue persists. ‘import Grasshopper’ was working perfectly fine until I tried to launch script A from another subprocess, now it is unrecognized.

How do I fix this?

That’s strange. As a first step you might check if it shows up in the references:

Thanks @AndersDeleuran that helps me narrow it down.

Maybe I just don’t understand when I can ‘import Grasshopper’

‘import Grasshopper’ is successful after I manually launch Grasshopper in Rhino, but the import fails if I call it before

Before launching Grasshopper manually:

After launching Grasshopper manually:

Is there a way to reference the Grasshopper module before / without launching Grasshopper manually from Rhino?

Yes you could manually reference the assembly if it is not already. Something like this:

import clr
clr.AddReferenceToFileAndPath(r"C:\Program Files\Rhino 7\Plug-ins\Grasshopper\Grasshopper.dll")

Thanks! :slight_smile:

1 Like

No worries, hope all is well :partying_face:

1 Like