Import file in Python

Solution without adding sy.path.append(…) each time

  1. Run this in a Python node inside Grasshopper
import site
sps = site.getsitepackages()

for sp in sps:
    print(sp)

The output should look something like this

  • C:\Users\x\.rhinocode\py39-rh8
  • C:\Users\x\.rhinocode\py39-rh8\lib\site-packages
  1. Find the file named distutils-precedence.pth

Open it with the editor of your choice, where you will find something like

import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'stdlib') == 'local'; enabled and __import__('_distutils_hack').add_shim();
  1. Add this in the next line
import sys; sys.path.append(r"D:\proton\My files\grasshopper\python")
  1. Restart Rhino and verify
import sys
paths = sys.path

for path in paths:
    print(path)
  1. Add your *.py Files

  1. Enjoy

1 Like