Adding local packages to Python scripts

Hi All,

I am attempting to import a .py file to access functions. It works if the file is in the same folder, but I want all my libraries in a separate folder.

The following page recommends using the # env option, but I can’t get this to work.

env: C:/Users/smthspce/CodeRepos/PersonalRepos/smthspce_RhinoPython/00_Libraries/

import MathLibrary

It says "No module named ‘MathLibrary’

Has anyone else had success with this, or has an alternative approach?

Thanks
Chris

Hi @Chris_Bamborough,

in the old R7 script editor (_EditPythonScript) you can define module search paths under:

Tools > Options > Files > Module Search Paths

Something similiar will be available with the new script editor in Rhino 8.

Alternatively you could try to append your path to sys.path like below:

import sys
search_path = r"C:\MyFolder\MySubFolder"
sys.path.append(search_path)

_
c.