Site Tools


Using Numpy SciPy and other Cpython libraries in GHPython

There are ways to use Numpy and Scipy within the GHPyton component in Grasshopper.

Cpython Remote for Grasshopper

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. See below for more instructions on installation and setup for Rhino 5.

COMPAS

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).

CPython for Grasshopper

Cpython plugin for Grasshopper Aug 1st, 2017 GHCPython Github


CPython Remote

GH Python Remote is a special component that lets you use regular Python 2.7.5 code directly in the Rhino 5 GHPython component, like importing Numpy, Scipy, matlplotib et al.

Rhino 5 will run IronPython. The Anaconda install can run any CPython 2.

Setting this up takes many steps:

  1. Install Grasshopper for Rhino 5
  2. Setup an AnaConda virtual environment running Python 2.7.5, Nunpy, SciPy etc….
  3. Install GHPython for Grasshopper
  4. Update the Rhino Python engine used by Grasshopper to the release 2.7.5
  5. Install GHPython Remote in Grasshopper
  6. Run the GhPython Remote sample

Install Grasshopper for Rhino 5

  1. Make sure the Rhino 5 is SR9. Check Help pulldown > About Rhinoceros > Lower right.
  2. Install Grasshopper or make sure the current Grasshopper is Build 0.9.0076 by opening Grasshopper > Help pulldown > About Grasshoppper.
  3. Download and install GHPython version 0.6.0.3. The install can be completed by dragging and dropping the GHA file onto the Grasshopper Canvas.

and extract the folder into the documents folderin windows.

Update the Rhino 5 IronPython version

Rhino uses IronPython 2.7.5. Rhino 5 requires this version of IronPython, but needs for this project needs a 'release' version of Python.

  1. To check the current version of Python that Rhino is using. On the rhino command line type “EditPythonScript”.
  2. Within the Python editor run the following code:
    import sys
    print sys.version_info
  3. The display will report something like this:
    sys.version_info(2, 7, 0, 'beta', 0)
  4. If the version is does not list 'final' or is not 2.7.5, then install a release version of Python 2.7.5. Take note of the path that python is installed.
  5. After installing Python, Open Rhino and run the EditPythonScript again.
  6. In the script editor go to the Tools pulldown > Options… > File Tab.
  7. Add these 3 paths to the Module Search Paths:
    %installed path%\IronPython275
    %installed path%\IronPython275\Lib
    %installed path%\IronPython275\DLLs
  8. Restart Rhino
  9. To check the current version of Python that Rhino is using. On the rhino command line type “EditPythonScript”.
  10. Within the Python editor run the following code:
    import sys
    print sys.version_info
  11. Now the script should display the full release version information:
    sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0)

Setup an AnaConda virtual environment running CPython 2.7.5

1) Install Anconda Virtual Environment:

  1. Do not worry about checking the Options about setting the Path or the default Python interpreter to Anadconda

2) Setup a new Anaconda Environment

  1. Once installed, start up the Anaconda Prompt App. I find it best to set “Run as Administrator”
  2. Setup a new Rhinoremote environment by using the command
    conda create -n rhinoremote python=2.7
  3. Activate the new environment:
    conda activate rhinoremote
  4. Install Numpy, Scipy. Use this to install any other CPython libraries in the Rhinoremote envoronment:
    conda install numpy
    conda install scipy
  5. It looks like the new pip major version (>=10.0.0) finally removed the “pip.main” functionality that many are using but that was not officially supported… In turns this breaks the installation script. For now, you should be able to move one step further by downgrading pip to 9.0.3:
    python -m pip install pip==9.0.3
  6. Install gh-python-remote in Anaconda - 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. The extra options are necessary to be able to get the pre-release version of rpyc.
    pip install gh-python-remote --upgrade --process-dependency-links --no-binary=:all:
    python -m ghpythonremote._configure_ironpython_installation
  7. Record the location of the rhinoremote environment by using the conda command:
    conda env list

It should show something like “C:\Users\steve\AppData\Local\conda\conda\envs\rhinoremote”

Using GH Python Remote

  1. Start the Annaconda Console Application.
  2. Activate the rhinoremote environment:
    conda activate rhinoremote
  3. Start Rhino and Grasshopper. Open the Documents/ghpythonremote-1.1.X\ghpythonremote\examples\GH_python_remote.ghx
grasshopper/cpython.txt · Last modified: 2018/08/08 by scottd