Installing Python libraries in Grasshopper

Hi, I am trying to import a script that I made in Python 3.6.5 into Grasshopper using the Python script. In my code I use the following libraries:

  • Numpy
  • Pillow
  • Matplotlib
  • OR-Tools
  • SciPy

There is any way to use them also in the Python component in grasshopper?
thanks

I think GH PYTHON REMOTE is what you’re looking for.

Hi,
I used GhC_Python to use these libraries in gh, and it works pretty well ! It just has some trouble outputing gh format data (lists, trees). The workaround is to put a classical GhPython component behind to get the right format.

Cheers

So using this component I can run my script as when I run it in IDLE? With all differents library?

GH Python remote seems to only work for python 2.7. Is it possible to get GH Python remote to work for Python 3.x?

@leland.curtis unfortunately any Python running in Rhino or GH is limited to 2.7 because of IronPython. See this comment on Food4Rhino.

hello

Other options include Rhino Inside CPython (needs Rhino 7 WIP) and Rhino3dm (limited capabilities) , possibly combined with rhino compute for the good stuff

-Graham

Awesome! Thank you :slight_smile:

Hey, I am curious if there is any new possibility with Python for Grasshopper in Rhino 7 - I guess it is still based on IronPython?

In other words, is there now a workaround to handle Python modules within Grasshopper that are based on Python 3.7+ … thx.

Yes, still IronPython.

I think everything relevant was already mentioned above.

So this means basically no? I guess the Rhino Inside approach is not suitable if you want to combine it with Grasshopper as it just allows you to work with Rhino Geometry.

GH Python Remote and the CPython add-on allow limited use of CPython in Grasshopper.

Installing Python packages in Rhino 8 / Grasshopper (CPython)

Rhino 8 uses its own Python environment. You can install PyPI packages directly into it using pip from PowerShell.

Example (NumPy):

& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install numpy

Other useful libraries for Rhino / Grasshopper / geometric computing:

NumPy (fast numerical arrays)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install numpy

SciPy (scientific computing / optimization)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install scipy

Pandas (data processing / tables)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install pandas

Shapely (computational geometry operations)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install shapely

Scikit-learn (clustering / regression / ML)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install scikit-learn

NetworkX (graph algorithms / topology)
& “C:\Users\username.rhinocode\py39-rh8\python.exe” -m pip install networkx

Test inside a Grasshopper Python component:

import numpy as np
print(np.version)

Note: the & operator is required in PowerShell because the Python path contains spaces.

use this method , working properly inside rhino 8 grasshopper Cpython

You can also use the script package manager:

Hm, but always gives errors, that’s why i choose to install vai ps.

You should probably report those, to help @eirannejad fix them.