Grasshopper

algorithmic modeling for Rhino

If I import a python module into the GhPython component, using a python "import" statement, the python engine doesn't seem to ever reevaluate that module unless I restart Rhino. It seems to cache the imported module until Rhino is restarted. Closing Grasshopper does not help.

If I change the inputs to the ghPython component, the module's value is not updated.

Even if I remove the module's path from sys.path, set the module's value to None and re-import it, the module still has the same cached value and does not update

Even if I delete the module and do the above, it does not change the module's value in the ghPython component.

Also, deleting the GhPython only ghPython component on the canvas and rewriting the script does not help. Nor does closing and reopening the grasshopper file.

This makes it a huge pain to develop any sort of external python module that works with python in Grasshopper. Grasshopper could make a great test environment for python packages generally, because the inputs can be changed dynamically, but my inability to update a module is really preventing progress.

Is there a way to manually refresh the module in a script?

Views: 2764

Replies to This Discussion

Hello Ben
Sorry if I'll be quick, I'm in Berlin for the Design Modeling Symposium.

Have you tried the reload(module_variable) function?

Giulio

Hi Giulio,

I had forgotten that. Thank you for reminding me.

I tried it, but it does not work either.

Benjamin,

Have you solved this issue? Some one year later i am running into exactly the same thing. Ideas? 

Thank you,

Hi Konrad,

I have been using Giulio's solution for some time.
You just have to add the reload function after your import call:

import somemodule
reload(somemodule)  # insert additionally, once your somemodule.py file has been changed

# do something...

Hi Dordie,

But does that mean that you have to add a reload function in the ghPython component for every time that the "somemodule.py" has been changed or did I misunderstand something? Sounds like an big effort...

 

Thanks,

Samuel 

No, you just add it once. In this way each time you change something in your module.py file, the module would be reloaded.

Yes, that's what I would do, too. Just keep it there while I am editing my code. Once I am done, remove the line...

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

thanks

Samuel

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service