mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
117 stars 34 forks source link

Wish: Add Grasshopper libraries folder to default module paths read by GHPython #66

Closed AndersDeleuran closed 9 years ago

AndersDeleuran commented 10 years ago

Hi All,

We just finished a workshop in which we issued several Python modules. To install these we had the students place the modules in the default Grasshopper library folder:

C:\Users\UserName\AppData\Roaming\Grasshopper\Libraries

The main motivation being that they were already asked to install the GHPython and Kangaroo dependencies and thus "knew" this folder and could easily access it from the Grasshopper GUI (File -> Special Folders -> Components Folder). To read the modules we would add the folder path using sys.path.append(ghLibPath) in the respective scripting components.

While this works it would have been great if it was already added to the path. I am aware that one can add a folder using the "EditPythonScript" editor and "Tools -> Options -> Files". However this interface is clunky at best (try adding a folder under C:\users on a vanilla Windows machine). I am also aware that RhinoPython/GHPython already reads this path:

C:\Users\UserName\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts

However I think it is reasonable to assume that it is not only easier to ask "a user" to only install dependencies in one folder. But moreover I find myself experimenting with several GH assemblies using Python lately (mainly Kangaroo and Plankton).

For these reasons it would be great if the Grasshopper libraries folder would be added to the default module paths read by GHPython.

That went a bit long. Apologies :)

Best,

Anders

piac commented 10 years ago

There are two main issues that I can see relating to this and the other conversation we are having:

I am a bit reluctant about the first item, really, as there are already several places where the script looks (including the local folder) and it would be nice to hear people's opinions. Not always too many locations are a good idea (also too many locations get users confused). The second one I think is quite meaningful, really.

Giulio

AndersDeleuran commented 10 years ago

I have given it some further thought as well. In retrospect perhaps the idea of adding .py files to the gh library folder was probably not the best idea. I guess it was just the immediate workshop experience which had me bothered :)

The next time I will just have them place Python modules in:

C:\Users\UserName\AppData\Roaming\McNeel\Rhinoceros\5.0\scripts

Which is actually a pretty accessible folder using the EditPythonScript editor. That said, I would still claim that a less clunky interface for adding new paths is much needed ;)

Thanks Giulio,

Anders

piac commented 10 years ago

Just a minor comment on the ability to access that folder: you can also find it by typing:

%appdata%\McNeel\Rhinoceros\5.0\scripts

in a Windows Explorer address bar.

Giulio

AndersDeleuran commented 10 years ago

That is excellent, never knew about that! Thanks again..

AndersDeleuran commented 9 years ago

Hi Giulio. I would like to raise this one again.

I have been developing and issuing quite a lot of GHPython components lately which implement both .gha and .dll assemblies. These are placed in the Grasshopper library folder and I ask the user to add this path to the RhinoPython path using the method described here:

https://github.com/AndersDeleuran/ShapeOpGHPython

Now I don't why, but this seems to be a problematic issue every single time! I think it might be a combination of the clunky interface in the editpythonscript editor (i.e. a dropdown tree where you can't paste the path as a string) and the fact that userdata is a hidden folder.

So with that, I would really really appreciate it if the Grasshopper libraries path was hard coded to the default module paths read by GHPython

Really looking forward to trying out the Rhino 6 version by the way, looks great :)

Best,

Anders

piac commented 9 years ago

Hi Anders

this morning in my inbox I received both your request, and the request of help of another user who has trouble 'unloading' a module they loaded once. I am pretty sure that the issue is just that they have two .py files, and the wrong one is being loaded from an unexpected location.

So, adding more paths is something very costly in this perspective and I would really like to avoid it, if I can help it. I fully understand the needs of your special case, and therefore have this suggestion for you. If your library needs the special folder as a requirement, then why not add it automatically in your script? The facilities for this are in Grasshopper, GhPython and Python itself. You can write this:

import Grasshopper as gh
import sys

ghcompfolder = gh.Folders.DefaultAssemblyFolder
if ghcompfolder not in sys.path:
    sys.path.append(ghcompfolder)
piac commented 9 years ago

... and I still fully agree that the path editor should be accessible from GhPython and that it should be easier to add paths via copy/pasting. Thanks for the reminder. I've added these to our lists. http://mcneel.myjetbrains.com/youtrack/issue/GH-1760 http://mcneel.myjetbrains.com/youtrack/issue/RH-29209

AndersDeleuran commented 9 years ago

Thanks Guilio. I have been using the method where I add the path in the script. I have however also experienced that this does not always work (mainly on bootcamped Macs, didn't dig deeper into why). That said, having a simpler method for adding the path via the GHPython or editPythonScript editor would be a good solution I think. Thanks again :)

piac commented 9 years ago

Please report it if you see that happening again. I can test it, too: I am running a Bootcamped Mac now.

AndersDeleuran commented 9 years ago

I'll make sure to troubleshoot it and report back if/when it pops up again. I remember it also happening on a normal PC as far as I recall. Will keep an eye out.