Installing a GH-Python-Remote and Rhino.Python editor integrated environment:
One issue that I encountered while working on scripting projects in Rhinoceros is the use of numpy/scipy
within the Rhino
Python Editor, due to inconsistencies in the native builds of the packages; Rhino Python Editor is .NET native, and
the latest numpy/scipy distros are written in Python. Enthought started an ambitious project to translate the two modules into the IronPython framework, but abandoned them soon after because it proved to be extremely difficult. They managed
to create .eggs installations for the two but left them in a very early stage of the process and do not maintain them anymore. The following guide will help you install GHPython Remote, a powerful Grasshopper component that ports your
python libraries directly into Rhino, as well as an organized Anaconda environment and a proper linkage between Rhinoceros Python and your local installation.
From the developers:
GHPython 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.
GHPython Remote works by connecting GHPython to an external instance of Python that runs all the usual programs. This augments the GHPython component to get the best of both worlds: your code will be able to call both RhinoCommon
functions and regular Python packages from the same script. The dependencies are as limited as possible, and the installation is just to two command lines. The connection between GHPython and the remote Python is as fast as possible,
and does not slow down when the size of your objects increases.
The component is still very flexible. For example, it will also let you connect to Python servers running on external machines, bringing the power of the cloud to your Grasshopper. Another example: it also works the other way,
controlling Rhino and GHPython from an external Python program. And it's all open source!
- Install Grasshopper for Rhino 5
- Install GHPython for Grasshopper
- Update the IronPython engine used by Grasshopper to the release 2.7.5
- Install GHPython Remote in Grasshopper
- Setup an Anaconda virtual environment running Python 2.7.5, Numpy, Scipy, and all other packages you would like to use in Rhinoceros
- Install GHPython Remote in the Anaconda environment.
- Run the GHPython Remote sample
- Install Grasshopper for Rhinoceros 5.0 (Rhino 6.0 comes with Grasshopper, skip to GHPython Remote Installation).
- Download and install GHPython. The install can be completed by dragging and dropping the GHA file onto the Grasshopper Canvas (Rhino 6.0 comes with GHPython, skip to GHPython
- Download GHPython Remote
- Install Anaconda 3 for Windows running Python 2.7 (Make sure to perform a user installation, "Just for me", instead of system-wide one to prevent access issues in the ProgramData folder. Do not worry about checking the Options about
setting the PATH, just leave the box unchecked in the installation prompt)
- Setup a new Anaconda Environment:
- Once installed, start up the Anaconda Prompt App. Run as Administrator to avoid PATH inconsistencies
- Setup a new rhino-remote environment by using the command:
conda create -n rhino-remote python=2.7
- Activate the new environment:
conda activate rhino-remote
- Install Numpy, Scipy. Use this opportunity to install any other Python libraries in the rhino-remote environment, either via conda or pip:
conda install numpy
conda install scipy
- For this exercise, I also installed COMPAS, 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 of ETH Zurich, with the support of the National Centre for Competence in Research
on Digital Fabrication. Install it with the following:
conda install --channel "conda-forge" COMPAS or
pip install COMPAS
You can also install it by incorporating the conda-forge
channel in your list of channels in Anaconda:
conda config --add channels conda-forge
conda install COMPAS
While conda-forge is a very well maintained package repository, I avoided using the latter
approach because of inefficiencies in the default Environment Solver, which is parsing the list of available packages very slowly and is causing the Anaconda Prompt to hang on Solving Environment indefinitely.
- 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, which is the only one compatible with GHPython remote at the moment:
pip install gh-python-remote --upgrade --process-dependency-links
python -m ghpythonremote._configure_ironpython_installation (this will install in the default IronPython path that has been set by Rhino. It can be found
C:\Users\%User%\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython(814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib) for Rhinoceros 6.0. Adding a 5 at the end of the python command will perform the installation
for Rhinoceros 5.0.
- Record the location of the rhinoremote environment by using the conda command:
conda env list
The command should return something like “C:\Users\%User%\Anaconda3\envs\rhino-remote”
- Start Anaconda Prompt.
- Activate the rhino-remote environment:
conda activate rhino-remote
- Start Rhino and Grasshopper. Open the sample file GH_python_remote.ghx and mesh_smoothing.3dm
- Double-click on the Python location panel and input the location of your newly created rhino-remote environment. It should look very similar to what is shown here:
- Enter the modules you would like to import from the your Anaconda environment in the modules panel (break each entry with a return). For the purposes of this exercise, I imported compas through the grasshopper module, but you can
simply import it on the Python modules editor with
import compas. The only problematic modules in questions are numpy and scipy, among a few others, which cannot be imported directly. In those cases, you can import them
through the GPython Remote module and use the scriptcontext syntax to port them into your script:
- Switch the boolean toggle to True. A new terminal window will open, showing the porting procedure. Feel free to minimize it (but do not close it, as this is the background process that maintains your modules in the
- Navigate to the Python module:
- Double-click on the module to open the Python editor:
- Click OK or Test on the Python Editor to run the script. You should see something like this:
- You can bake the outgoing mesh to get a result that you can work with in Rhino.
Sources: Pierre Cuvilliers, Block Research Group, ETH Zurich, National Centre for Competence in Research
on Digital Fabrication, McNeel Rhinoceros.