Importing Python methods from my own library in Rhino and Grasshopper on macOS?

Hello,

I have created a Python file, called vector_methods.py, with handy functions that work in accordance with rhinoscriptsyntax. I want to be able to import my library in Rhino and Grasshopper Python, but I don’t know where I have to put the vector_methods.py?
To be clear I want to be able to import the methods of vector_methods.py in other Rhino Python scripts and within the Grasshopper Python Component. I have the latest version of Rhino 5 for macOS!

Any Ideas?

Thank you.

Put it in the same folder rhino stores it’s scripts in by default. When you type ‘_EditPythonScript’ rhino will show you the location. You can import any python file in the scripts folder into ghpython nodes and rhinopython scripts it’s as simple as writing

Import my module.py

In Rhino for Mac, ‘_EditPythonScript’ is an unknown command. It doesn’t open the Script Editor like on Windows. All you can do to run Python script is, use the command ‘RunPythonScript’, which just opens a system dialogue, where you can select your Python file and upon confirmation, Rhino will run it in the background.

Run this in a GhPython component, it will tell you all the locations the import statement searches in.

import sys
print '/n'.join(sys.path)

(you can also append to the sys.path like any other list to tell it to look in a specific location)

The main scripts folder should be in ~/Library/Application Support/McNeel/Rhinoceros/scripts

3 Likes

Thanks, qythium. Worked like a charm!