GithubHelp home page GithubHelp logo

pilcru / ghpythonremote Goto Github PK

View Code? Open in Web Editor NEW
121.0 16.0 37.0 5.42 MB

A two-way connector to use regular Python from IronPython in Rhino/Grasshopper, and vice-versa.

Home Page: https://github.com/pilcru/ghpythonremote

License: MIT License

Python 91.67% CSS 8.33%
python ironpython rhinoceros rhino3d rhino grasshopper grasshopper3d numpy scipy matlplotlib

ghpythonremote's Introduction

gh-python-remote

Connect an external python instance to Grasshopper, and vice-versa.
This lets you run any Python package directly from Grasshopper, including numpy and scipy!

https://raw.githubusercontent.com/Digital-Structures/ghpythonremote/9d6773fbc0cc31cc042b5622aadd607716e952f7/GH_python_remote_plt.png


Installation

Requires a Python 2.7 installation, not compatible with Python 3. Compatible with Mac and Windows with Rhino 7.

1. Install the software dependencies:

Before installing gh-python-remote in Rhino 7, you will need to install Python 2, Rhino 7, and open Grasshopper in Rhino 7 at least once.

Before installing gh-python-remote in Rhino 6, you will need to install Python 2, Rhino 6, and open Grasshopper in Rhino 6 at least once.

Before installing gh-python-remote in Rhino 5, you will need to install Python 2, Rhino 5, Grasshopper and GHPython, and drop the GHPython component on the Grasshopper canvas in Rhino 5 at least once.

Install the following:

Python 2.7:

gh-python-remote was developed with the Anaconda and Miniconda distributions in mind, but any Python 2.7 distribution works. If you already have Anaconda installed with Python 3, you do not need to reinstall it, you can create a virtual environment as explained below.

If you want to be able to name virtual environments in gh-python-remote by their conda name, select "Add conda to my PATH" when prompted during Anaconda's installation.

On Mac, the python distributed with the OS is outdated and difficult to use by the end-user. It is highly recommended to use a conda- or brew -based Python.

Python virtual environment (optional):

Isolate dependencies for each project by creating a new virtual environment. If you use Anaconda or Miniconda, creating a virtual environment is easy.

  • Open the Windows command prompt, or Mac terminal (or the Anaconda prompt if you chose not to add conda to your PATH during insallation)
  • Run the following command:
conda create --name rhinoremote python=2.7 numpy scipy

This will create a new virtual environment named rhinoremote, and install numpy and scipy in it.

Rhinoceros3D:

Version 7 is supported on Windows and Mac. Version 5 and 6 on Windows should work, but are not supported.

Grasshopper:

On Rhino 6 and 7, it is already installed. On Rhino 5, install version 0.9.0076. Open it at least once before continuing.

GH Python:

On Rhino 6 and 7, it is already installed. On Rhino 5, install version 0.6.0.3. On Rhino 5, drop it on the Grasshopper canvas at least once before continuing.

2. Install gh-python-remote:

From the Windows command prompt, or Mac terminal (or the special Anaconda, or Python prompt if pip is not in your path by default), run:

(If you are using a virtual environment, remember to activate it first. With the conda virtual environment from above, you would need to run conda activate rhinoremote in the command prompt.)

pip install gh-python-remote --upgrade
python -m ghpythonremote._configure_ironpython_installation

This will install gh-python-remote for Rhino 7, and install the gh-python-remote UserObject in all Grasshopper versions.

The ghpythonremote._configure_ironpython_installation script takes an optional location argument that can be 5, 6, 7 (default), or the path to a target IronPython package directory.

For example, to install for Rhino 5, replace the second command with:

python -m ghpythonremote._configure_ironpython_installation 5

To install to another location:

python -m ghpythonremote._configure_ironpython_installation ^
  "%APPDATA%\McNeel\Rhinoceros\7.0\Plug-ins\^
  IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib"

Usage

All the examples files are copied to %APPDATA%\Grasshopper\UserObjects\gh-python-remote\examples on Windows, and ~/Grasshopper/UserObjects/gh-python-remote/examples on Mac. You can also download them from the github repo.

From Grasshopper to Python

Step-by-step

  1. Open the example file GH_python_remote.ghx in Grasshopper, or drop the gh-python-remote component on the canvas.

  2. Use the location input to define the location of the Python interpreter you want to connect to.

  3. Use the modules input to define the modules you want to access in the GHPython component.

  4. Change run to True to connect.

  5. In the GHPython component, the imported modules will now be available via the sticky dictionary. For example if you are trying to use Numpy:

    import scriptcontext
    np = scriptcontext.sticky['numpy']

Notes

Creating remote array-like objects from large local lists is slow. For example, np.array(range(10000)) takes more than 10 seconds. To solve this, you need to first send the list to the remote interpreter, then create the array from this remote object:

import scriptcontext as sc
import ghpythonremote
np = sc.sticky['numpy']
rpy = sc.sticky['rpy']

r_range = ghpythonremote.deliver(rpy, range(10000))
np.array(r_range)

Additionally, Grasshopper does not recognize remote list objects as lists. They need to be recovered to the local interpreter first:

import scriptcontext as sc
import ghpythonremote
from ghpythonlib.treehelpers import list_to_tree  # Rhino 6 only!
np = sc.sticky['numpy']

a = np.arange(15).reshape((3,5))
a = ghpythonremote.obtain(a.tolist())
a = list_to_tree(a, source=[0,0])

ghpythonlib.treehelpers is Rhino 6 only, see the treehelpers gist for an equivalent implementation if you need it on Rhino 5.

Quick-ref:

* marks an input that is only available by editing the gh-python-remote UserObject, or in GH_python_remote.ghx.

Arguments:
*code (string):Path to the GH_to_python.py code file.
location (string):Path to a python executable, or to a folder containing python.exe, or the name of a conda-created virtual environment prefixed by conda:// (conda://env_name, requires conda available in your PATH). If empty, finds python from your windows %PATH%.
run (boolean):Creates the connection, and imports new modules, when turned to True. Kills the connection, and deletes the references to the imports, when turned to False.
modules (string list):List of module names to import in the remote python. They will be added to the scriptcontext.sticky dictionary, allowing them to be reused from other python components in the same Grasshopper document. Submodules (for example numpy.linalg) have to be added explicitly to this list to be available later, and importing the parent package is also required even if only the submodule is used.
*log_level (string from ['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']):
 Logging level to use for the local IronPython and the remote python instance.
*working_dir (string):Working directory for the remote python instance.
Returns:
out (string):Console output with DEBUG information.
linked_modules (string list):List of imported module names.
rpy (rpyc connection object):The object representing the remote Python interpreter.
import_statements (string):What to use in the GHPython component to actually use the imported modules.

From Python to Grasshopper

You can also use gh-python-remote to programmatically control a Rhinoceros instance, and connect to it via Python. Have a look at examples/python_to_GH.py for a full working example.


License

Licensed under the MIT license.

ghpythonremote's People

Contributors

pilcru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghpythonremote's Issues

Python 3+ support

Hi guys,

is there a workaround in order to get python 3 support?

I'm really looking a way to connect this to tensorflow and that only runs on python 3+.

I did try a workflow with gh_cpython, that worked well with tensorflow, but then I'm missing out on sc.sticky etc.

Missing example files

The example python_to_GH.py expects a GH user component TestClusterGHPR. However, ghpythonremote._configure_ironpython_installation does not copy this file to the User Objects folder. There are also other example files which are not copied anywhere.

example files missing after pip install

After following the instructions:

pip install gh-python-remote --upgrade --no-binary=:all:
python -m ghpythonremote._configure_ironpython_installation

My conda console tells me:

Successfully installed gh-python-remote-1.2.1 plumbum-1.6.7 rpyc-4.1.1
...
IOError: [Errno 2] No such file or directory: 'C:\\Users\\harry\\.conda\\envs\\py27\\lib\\site-packages\\ghpythonremote\\examples\\CPython_to_GH.py'

And these are the files in my examples folder:
image

It's strange that this happens since we already have these example files marked as package_data in the setup.py (here). Do we need to add them in the MANIFEST.in as well?

Make ghpythonremote compatible with Rhino 6

This should be just a matter of changing paths, although the question remains to install for both versions if possible or only one, when running python -m ghpythonremote._configure_ironpython_installation.

GH Python remote with Sympy

Hello,

I have a problem while import sympy in the GH Python through GH Python remote. The code is as below:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import ghpythonremote
sp = sc.sticky['sympy']

x = sp.symbols('x')
q = sp.symbols('q', cls=Function)
Mq = sp.symbols('Mq', cls=Function)
Vq = sp.symbols('Vq', cls=Function)
diffeqbmq = Eq(Mq(x).diff(x,x), -q)
BMq = dsolve(diffeqbmq, Mq(x), ics = {Mq(0):0, Mq(l):0})
SFq = Eq(Vq(x),BMq.rhs.diff(x)) 

but the functions in Sympy such as Function, Eq, dsolve is not usable in gh python.
it shows a warning: name 'Function' is not defined.

Could I ask how to solve it?

"Location" is inside Docker container

Thank you for this nice package.
I have a quite complicated situation.
I have a docker container that contains a python venv and i want to execute commands from my Rhino python code.
Is this currently possible with this library or dou you know how to achieve this?

Furthermore, Rhino 8 is adding some newer CPython functionality do you think it is feasible to enable newer Python versions here?

Thanks!

rpyc error on handling string input

rpyc seems to have some problems with delivering string input, but the problem symptoms varies depending on the python packages.

All the examples below are run on a 64-bit Windows 10 machine with Rhino 6, conda env python 2.7, gh-python-remote 1.2.1.

Error script 1: numpy.fromstring

import scriptcontext as sc
np = sc.sticky['numpy']

np.fromstring(str('1 2'), dtype=int, sep=str(' '))

Result 🔴 :

Runtime error (Exception): data type not understood

Traceback:
  line 102, in value, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
  line 458, in sync_request, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 76, in syncreq, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 247, in __call__, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 17, in script

Error script 2: pycddlib

import scriptcontext as sc
import ghpythonremote
cdd = sc.sticky['cdd']

mat = cdd.Matrix([[2,-1,-1,0],[0,1,0,0],[0,0,1,0]], number_type='fraction')
# f_converted = ghpythonremote.deliver(rpy, 'fraction')
# mat = cdd.Matrix([[2,-1,-1,0],[0,1,0,0],[0,0,1,0]], number_type=f_converted)

The ghpythonremote.deliver conversion results in the same error.

Result 🔴 :

Runtime error (Exception): Argument 'number_type' has incorrect type (expected str, got unicode)

Traceback:
  line 102, in value, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
  line 458, in sync_request, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 76, in syncreq, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 247, in __call__, "C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 5, in script

But, the string input works in some cases... For example, the [scipy.optimize.minimize_scalar](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize_scalar.html#scipy.optimize.minimize_scalar):
Passed script:

import scriptcontext as sc
scipy = sc.sticky['scipy']
scipy.optimize = sc.sticky['scipy.optimize']

def f(x):
    return (x - 2) * x * (x + 2)**2

res = scipy.optimize.minimize_scalar(f, bounds=(-3, -1), method='bounded')
print(res)

Result 💚 :

     fun: 3.2836517984978577e-13
 message: 'Solution found.'
    nfev: 12
  status: 0
 success: True
       x: -2.000000202597239

importing methods from "ortools" library

Hi,

I'm facing an issue when trying to load a specific method from the Google "Or-Tools" library.

I have installed the library in the correct environment ("rhinoremote") and loading it from there works fine:
Annotation 2020-01-11 163020

I can import ortools.sat.python via the sticky dictionary but can't seem to figure out how to access the cp_model method from there:

Annotation 2020-01-11 164425

For clarity, the tree structure:

ortools__
         sat__
              python__
                       __init__.py
                       cp_model.py
                       cp_model_helper.py
                       vizualisation.py

Am i missing something obvious or is it a limitation from GhPythonRemote ?

Issues since rpyc update 4.1.0

This is a continuation of the comment I left on the plugin page. I created rhinoremote2 virtualenv and it installed fine. No errors apart from deprecation warnings. This is the full error message when I try and run the example file (Ì changed the location to conda://rhinoremote2)

DEBUG: ghpythonremote.connectors:
Using python executable: C:\Users\john\.conda\envs\rhinoremote2\python.exe
DEBUG: ghpythonremote.connectors:
Using rpyc_server module: C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\pythonservice.py
DEBUG: ghpythonremote.connectors:
Using port: 52348
DEBUG: ghpythonremote.connectors:
Using log_level: DEBUG
DEBUG: ghpythonremote.connectors:
Using working_dir: C:\Users\john\AppData\Roaming\Grasshopper\UserObjects\gh-python-remote\examples
INFO: ghpythonremote.connectors:
Connecting...
DEBUG: ghpythonremote.connectors:
Connecting. Timeout in 10 seconds.
Runtime error (EndOfStreamException): EOFError

Traceback:
  line 55, in recv, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\channel.py"
  line 100, in value, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
  line 76, in syncreq, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 161, in __getattribute__, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 217, in _install, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
  line 213, in on_connect, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
  line 105, in _connect, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
  line 44, in connect_channel, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 56, in connect_stream, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 99, in connect, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 75, in connect, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\classic.py"
  line 36, in __init__, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"
  line 256, in read, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\stream.py"
  line 374, in serve, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 47, in wait, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
  line 455, in sync_request, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 117, in _get_connection, "C:\Users\john\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"
  line 49, in script

Problem running example files

Running in a 2.7 environment ( conda://rhinoremote ) as directed in the guide and from a fresh anaconda3 install, I'm having problems running the GH to python remote example.

I have the following modules:

import scriptcontext as sc
scipy = sc.sticky['scipy']
numpy.linalg = sc.sticky['numpy.linalg']
numpy = sc.sticky['numpy']

I get the following error:

0. Runtime error (KeyNotFoundException): numpy
Traceback: line 3, in script

Any help/guidance would be much appreciated

thanks
anders

Grasshopper crashes when adding time and datetime libraries

Hi, I can successfully add time and datetime to the modules, but once I try to type import the following script into my GHPython Script:
import scriptcontext time= scriptcontext.sticky['time'] datetime= scriptcontext.sticky['datetime']
The whole Rhino and Grasshopper crashes. Any idea why this would be happening? I also noticed that this happens when I try to import csv besides time and datetime. Meaning this doesn't happen when a GHPython Script only has time and datetime.

"No handlers could be found for handler "GH..."" in CPython to GH context

Part of #29 seemed to be something else than just selecting a Rhino version in CPython to GH. there is also that:

there is a bug in the example you show, I'm guessing a mismatch in exception handling settings in rpyc between the two interpreters,

which also shows up in the Rhino command line in the screenshot. Investigate...

Connecting to Python from GH does not work on IronPython 2.7.0 (Rhino version)

(From email, food4rhino)

This happens only when using the IronPython version included in Rhino (2.7.0), adding the IronPython 2.7.5 libraries to Rhino fixes the issue. When trying to connect, fails with:

10. Runtime error (MissingMemberException): 'module' object has no attribute 'async'

11. Traceback:

  line 117, in _get_connection, "C:\Users\Alex\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"

  line 36, in __init__, "C:\Users\Alex\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"

  line 49, in script

When the async import is fixed, fails with:

11. Runtime error (TypeErrorException): sequence item 1: expected bytes or byte array, str found
12. Traceback:
  line 508, in sync_request, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 549, in root, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 100, in _connect, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
  line 70, in connect, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\classic.py"
  line 117, in _get_connection, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"
  line 49, in script
  line 319, in dump, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\brine.py"
  line 235, in _send, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 266, in _send_request, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 195, in on_connect, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
  line 43, in connect_channel, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 54, in connect_stream, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 93, in connect, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
  line 36, in __init__, "C:\Users\pcuvil\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"

ghPythonRemote for Python v3+ ?

Any chance an update for python3 could be available to tap into external data and use the powerful processing capacity of python, like pandas, numpy, etc and some arduino stuff?

Installing v1.1.1 fails when git is not installed on the path

(From email)

Trying to install v1.1.1 on a computer where git isn't installed fails:

Collecting gh-python-remote Using cached gh-python-remote-1.1.1.tar.gz DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.

Collecting rpyc>=3.4.5 (from gh-python-remote) Cloning https://github.com/pilcru/rpyc.git (to v3.4.5) to c:\users\alex\appdata\local\temp\pip-build-tzllou\rpyc

            Error [Error 2]。 while executing command git clone -q https://github.com/pilcru/rpyc.git c:\users\alex\appdata\local\temp\pip-build-tzllou\rpyc Cannot find command 'git'

Python 3.5/3.6

Hi,

First of all thanks for this amazing plugin!

I was wondering if you plan support for python 3 version anytime soon? It would open a lot of possibilities to certain areas.

Kind regards,
Theodore.

Investigate if --process-dependency-links is still needed

This is a deprecated option already in pip v9, so getting rid of it would be great and would make updating the pip dependency safer. It seems I was only using it when installing a custom build of rpyc, so maybe it's useless now.

Install gh-python-remote

Hi,

I run into this issue while trying to install gh-python-remote.

C:\Users\mag>pip install gh-python-remote --upgrade
ERROR: Could not find a version that satisfies the requirement gh-python-remote (from versions: none)
ERROR: No matching distribution found for gh-python-remote

What am I missing?

Thanks for your help!

Best,
Gian

CPython_to_GH.py invoke Rhino 5.0 in a RH6 context

Problem

I'm trying to test the CPython_to_GH.py example with Rhino 6.0.

What happened

I installed ghpythonremote in my conda env (python2.7, activated), and the ironpython configuration seems to be set up properly, with the console telling me the following:

> python -m ghpythonremote._configure_ironpython_installation
The gh-python-remote package will be installed in Rhino IronPython with the command:
C:\Users\harry\.conda\envs\py27\python.exe -m pip install --upgrade --target=C:\Users\harry\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib --no-binary=:all: --no-compile --ignore-requires-python gh-python-remote
...
Successfully installed gh-python-remote-1.2.1 plumbum-1.6.7 rpyc-4.1.1
INFO:Copied example files to C:\Users\harry\AppData\Roaming\Grasshopper\UserObjects\gh-python-remote

Notice that the IronPython of Rhino 6 is correctly identified above.

But if I run python CPython_to_GH.py in the path examples, Rhino 5 will be invoked and the following error shows up:

image

Well, I did python -m ghpythonremote._configure_ironpython_installation 5 as well. Before I did that, the error was simply "cannot locate module ghpythonremote".

Am I doing anything wrong here? I feel like there should be a parameter in the PythonToGrasshopperRemote class to let it know that we are dealing with RH5 or RH6, if both are installed in the system.

Delivering complex objects to the remote fails if the remote cannot unpickle them

For example, trying to deliver a (remote) numpy array. Probably this does not even make sense: we shouldn't deliver something that is already on the remote. Similarly, sending b"a" from IronPython 2 to CPython 2 won't work because it represents a call to bytes(u'a', 'latin-1') in IronPython, that CPython has no chance of understanding since bytes == str, which only takes one argument (no encoding).

But maybe this might hint at other issues when passing around netrefs or function calls.

>>> np = sc.sticky['numpy']
>>> rpyc.utils.classic.deliver(rpy, np.array(10))

Runtime error (Exception): TypeError
Traceback:
  line 516, in sync_request, "C:\Users\pcuvil.WIN\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 78, in syncreq, "C:\Users\pcuvil.WIN\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 212, in __call__, "C:\Users\pcuvil.WIN\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 292, in deliver, "C:\Users\pcuvil.WIN\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\classic.py"
  line 58, in script

--- Remote traceback: ---
Exception caught
Traceback (most recent call last):
  File "c:\tools\anaconda3\envs\rhinoremote\lib\site-packages\rpyc\core\protocol.py", line 342, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File "c:\tools\anaconda3\envs\rhinoremote\lib\site-packages\rpyc\core\protocol.py", line 638, in _handle_call
    return obj(*args, **dict(kwargs))
TypeError: ('loads() argument 1 must be string, not unicode', <built-in function loads>, (u"cnumpy.core.multiarray\n_rec
onstruct\np1\n(cnumpy\nndarray\np2\n(I0\ntS'b'\ntRp3\n(I1\n(tcnumpy\ndtype\np4\n(S'i4'\nI0\nI1\ntRp5\n(I3\nS'<'\nNNNI-1\
nI-1\nI0\ntbI00\nS'\\n\\x00\\x00\\x00'\ntb.",))
>>> rpyc.utils.classic.deliver(rpy, b"a")
(Same local traceback)

--- Remote traceback ---
Exception caught
Traceback (most recent call last):
  File "c:\tools\anaconda3\envs\rhinoremote\lib\site-packages\rpyc\core\protocol.py", line 342, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File "c:\tools\anaconda3\envs\rhinoremote\lib\site-packages\rpyc\core\protocol.py", line 638, in _handle_call
    return obj(*args, **dict(kwargs))
TypeError: ('str() takes at most 1 argument (2 given)', <type 'str'>, (u's', u'latin-1'))

Forcing casting to bytes in rpyc.utils.classic.obtain or rpyc.core.netref.__array__ doesn't fix it.

MacOS compatibility

Hello !

I read this is only compatible for Windows.
Am I right if I say making it work under MacOS is only a question of path syntax in the "helpers.py" ?

Thanks !

Using Numba

Dear @pilcru,

First let me thank you for this wonderful tool that is GHPythonRemote.

I would like to know if it is possible to use Numba with it and if so, how.
Importing it doesn't seem to be an issue but adding a @jit decorator to a function returns an error.

Example test:

nb = scriptcontext.sticky['numba']
jit = nb.jit

@jit
def f(x, y):
    return x + y

f(24, 167)

Returned error:

Runtime error (Exception): NotImplementedError

Traceback:
  line 58, in script
  line 102, in value, "C:\Users\solub\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
  line 458, in sync_request, "C:\Users\solub\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
  line 76, in syncreq, "C:\Users\solub\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
  line 247, in __call__, "C:\Users\solub\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"

Installation issue - Runtime error (ArgumentTypeException): expected buffer, got bytes

Hi,
Thank you for your reply on Food4Rhino.
I am trying to use python remote on Rhino 5 SR13 and GH 0.9.0076. Python 2.7 Anaconda2.
I followed the step of the installation but when I open the example file GH_python_remote and change the paths I get this error message:

DEBUG: ghpythonremote.helpers:
Directly trying python executable at C:\Users\Hp\Anaconda2\envs\rhinoremote

DEBUG: ghpythonremote.connectors:
Using python executable: C:\Users\Hp\Anaconda2\envs\rhinoremote\python.exe
DEBUG: ghpythonremote.connectors:
Using rpyc_server module: C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\pythonservice.py
DEBUG: ghpythonremote.connectors:
Using port: 50011
DEBUG: ghpythonremote.connectors:
Using log_level: DEBUG
DEBUG: ghpythonremote.connectors:
Using working_dir: C:\Users\Hp\Downloads\ghpythonremote-1.3.1\ghpythonremote-1.3.1\ghpythonremote\examples
INFO: ghpythonremote.connectors:
Connecting...
DEBUG: ghpythonremote.connectors:
Connecting. Timeout in 10 seconds.
Runtime error (ArgumentTypeException): expected buffer, got bytes
Traceback:
line 469, in sync_request, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
line 105, in _connect, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
line 44, in connect_channel, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
line 99, in connect, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
line 141, in _get_connection, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"
line 54, in script
line 267, in write, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\stream.py"
line 74, in send, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\channel.py"
line 259, in _send, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
line 475, in _async_request, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
line 493, in async_request, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
line 502, in root, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\protocol.py"
line 213, in on_connect, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\service.py"
line 56, in connect_stream, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\utils\factory.py"
line 53, in init, "C:\Users\Hp\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\ghpythonremote\connectors.py"

Thank you in advance for your help

On MacOS, `get_python_from_path` fails -- does not follow symlinks?

Reported here https://discourse.mcneel.com/t/solve-the-error-that-gh-pythonremote-dont-work-in-mac/125455

It appears that the get_python_from_path() function does not manage to get to the proper python2.7 file from the file or folder passed as argument. Reported errors are:

“Location format for /Users/xxx/anaconda3/envs/xxxx/bin/”
did not match expected format: “method://env_name”(need more than 1 values to unpack).Falling back to getting python path from MacOS $PATH."

or

“Runtime error (RuntimeException): Remote python /Users/xxx/anaconda3/envs/xxxx/bin/python failed on launch. Does the remote python have rpyc installed?”

or

"no mudule named xxx"

Runtime error (ImportException): No module named ghpythonremote

Hi @pilcru! Sorry to bother you, but i seem to be stuck at the installation step and really would like to try this amazing plugin.
I've followed meticulously the installation guide, but i'm also very new to all of this so i may do miss something easy.
Basically i've installed Anaconda3 (selecting "Add conda to my PATH"), created the env rhinoremote, activated it and run the provided commands.
Problems seem to happen when running the ghpyr configure ironpython installation: i've tried running the general one and the one with a specific folder, but this is what shows (in the conda prompt, win cmd prompt or powershell)

(rhinoremote) C:\Users\PREDATOR>conda env list
# conda environments:
#
base                     C:\Users\PREDATOR\anaconda3
rhinoremote           *  C:\Users\PREDATOR\anaconda3\envs\rhinoremote


(rhinoremote) C:\Users\PREDATOR>python -m ghpythonremote._configure_ironpython_installation ^
Ancora? "%APPDATA%\McNeel\Rhinoceros\7.0\Plug-ins\^
Ancora? IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib"
The gh-python-remote package will be installed in Rhino IronPython with the command:
C:\Users\PREDATOR\anaconda3\envs\rhinoremote\python.exe -m pip install --upgrade --target=C:\Users\PREDATOR\AppData\Roaming\McNeel\Rhinoceros\7.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib --no-compile --ignore-requires-python gh-python-remote
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting gh-python-remote
  Using cached https://files.pythonhosted.org/packages/0b/15/757df4424310efdfff9ed0fc314a613ef76d085067ab7666be90b3895556/gh_python_remote-1.4.4-py2-none-any.whl
Collecting rpyc==4.1.5
  Using cached https://files.pythonhosted.org/packages/36/a7/7898de583e17202ce02ac7ecffdbed95c72a6cebe468c1ee6fc94fc20933/rpyc-4.1.5-py2-none-any.whl
Collecting plumbum
  Using cached https://files.pythonhosted.org/packages/5f/c9/67b40a607f9815275c7867f9ec60700f442c186d3cca235156cb4fa19c33/plumbum-1.8.0.tar.gz
ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\cli\base_command.py", line 153, in _main
    status = self.run(options, args)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\commands\install.py", line 382, in run
    resolver.resolve(requirement_set)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\legacy_resolve.py", line 201, in resolve
    self._resolve_one(requirement_set, req)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\legacy_resolve.py", line 365, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\legacy_resolve.py", line 313, in _get_abstract_dist_for
    req, self.session, self.finder, self.require_hashes
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\operations\prepare.py", line 224, in prepare_linked_requirement
    req, self.req_tracker, finder, self.build_isolation,
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\operations\prepare.py", line 49, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\distributions\source\legacy.py", line 34, in prepare_distribution_metadata
    self.req.load_pyproject_toml()
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\req\req_install.py", line 537, in load_pyproject_toml
    str(self)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_internal\pyproject.py", line 66, in load_pyproject_toml
    pp_toml = pytoml.load(f)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_vendor\pytoml\parser.py", line 11, in load
    return loads(fin.read(), translate=translate, object_pairs_hook=object_pairs_hook, filename=getattr(fin, 'name', repr(fin)))
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_vendor\pytoml\parser.py", line 24, in loads
    ast = _p_toml(src, object_pairs_hook=object_pairs_hook)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_vendor\pytoml\parser.py", line 341, in _p_toml
    s.expect_eof()
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_vendor\pytoml\parser.py", line 123, in expect_eof
    return self._expect(self.consume_eof())
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\pip\_vendor\pytoml\parser.py", line 163, in _expect
    raise TomlError('msg', self._pos[0], self._pos[1], self._filename)
TomlError: c:\users\predator\appdata\local\temp\pip-install-pefua3\plumbum\pyproject.toml(69, 1): msg
Traceback (most recent call last):
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\site-packages\ghpythonremote\_configure_ironpython_installation.py", line 40, in <module>
    subprocess.check_call(pip_cmd)
  File "C:\Users\PREDATOR\anaconda3\envs\rhinoremote\lib\subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Users\\PREDATOR\\anaconda3\\envs\\rhinoremote\\python.exe', '-m', 'pip', 'install', '--upgrade', '--target=C:\\Users\\PREDATOR\\AppData\\Roaming\\McNeel\\Rhinoceros\\7.0\\Plug-ins\\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\\settings\\lib', '--no-compile', '--ignore-requires-python', 'gh-python-remote']' returned non-zero exit status 2`

Also i can tell you that there is no file in: "%APPDATA%\McNeel\Rhinoceros\7.0\Plug-ins^
IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib" nor in "%APPDATA%\Grasshopper\UserObjects\gh-python-remote\examples" (but i do find them in rhinoremote env folder).
No ghpythonremote components appear, but i can drag it on from rhinoremote env folder as well (but as you can imagine, it doesn't work and outputs: Runtime error (ImportException): No module named ghpythonremote). I've tried giving the envlist path for the location input, but also doesn't work.

I really hope i'm not wasting your time with something really silly to solve, but i can't find what i'm doing wrong.

Remote console remains empty on Windows 7

(From food4rhino)

Running ghpythonremote in windows 7, GH to Python, the console window that opens remains empty. The remote traceback is lost on errors, it is not redirected to GH.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.