There are three ways to use Numpy and Scipy within the GHPyton component in Grasshopper: GH Python Remote, COMPAS, and GHCPython.
This guide only details usage of the first one, GH Python Remote.
The main reasons behind this choice against the other two are:
GH Python Remote is a special component that lets you use regular Python code directly in the GHPython component, like importing Numpy, Scipy, matlplotib et al. It is developed by Pierre Cuvilliers at MIT.
COMPAS is an open-source, Python-based computational framework for collaboration and research in architecture, engineering and digital fabrication. It is developed by the Block Research Group (https://block.arch.ethz.ch) of ETH Zurich (http://www.ethz.ch).
Instructions to connect from Grasshopper to CPython
Instructions to control Rhino from CPython
CPython plugin for Grasshopper Aug 1st, 2017 GHCPython Github
Official installation instructions are available on the plug-in's homepage. This guide is an attempt to make these more accessible for beginner Python users.
GH Python Remote needed is a special component that lets you import and use any Python 2 package, like Numpy or Scipy, directly in the Grasshopper Python component. Because Rhino runs IronPython, which is limited in the plugins it can import, some plugins do not work with it. GH Python Remote will connect Rhino to an external CPython interpreter to overcome this limitation.
Setting this up takes several steps:
1) Install Anaconda python distribution:
2) Setup a new Anaconda Environment
conda create -n rhinoremote python=2.7
conda activate rhinoremote
conda install numpy conda install scipy
conda env list
It should show something like “C:\Users\steve\AppData\Local\Continuum\anaconda3\envs\rhinoremote”.
Still in the Anaconda prompt with the rhinoremote environment activated, run:
pip install gh-python-remote --upgrade --no-binary=:all: python -m ghpythonremote._configure_ironpython_installation
The first line installs gh-python-remote in the current Python interpreter. The second tries to find your Rhinoceros IronPython installation, and install gh-python-remote there.
import scriptcontext np = scriptcontext.sticky['numpy']