Showing matplotlib plots in GH Python Remote is a little weird: when plt.show() is executed a graph window will show up, and that statement will only return when the plot is closed by pressing “q” on the keyboard. The plot often opens in the background, so it’s easy to miss and you are left waiting in GH with a waiting wheel showing up.
While plt.show() is running, python is waiting on plt, Grasshopper is waiting on python, and after 30 seconds GH gives up waiting and forces the “result expired” error. GH Python Remote is normally still running at that point, with the plot somewhere in the background. If you quit the plot and run the script again (without restarting GH Python Remote), the error should go away when the script terminates properly (= when you quit the plot before the GH timeout).
Yes, you have to press “q” on the plot window for every time a plt.show() instruction is run. This is the same in a regular python script. The only difference here is that if you do not press “q” before the 30 seconds GH timeout, the rest of your script will not be executed.
I’m not exactly sure what you are trying to do, I’m guessing either get a collection of plots out of a single GH run, or have a plot update “live” as values in GH change?
If what you want is to get multiple plots, one for each value in a list for example, it might be easier to use matplotlib to output a static image, rather than a regular matplotlib plot.
If you are trying to follow the execution of a GH script, and have the plot change over time, you could try playing with interactive plots in matplotlib, but I’m not sure how well that plays out in GH Python Remote. I usually try to get all my live visualization done in Rhino/GH. Here are some pointers on interactive/non-blocking graphs: https://github.com/matplotlib/matplotlib/issues/12692/
I didn’t notice you replied but I already fixed it! Thanks!
Now I’m struggling to add more modules, other than the numpy and scipy. Matplotlib does not load, although I have installed it properly. I wanted to try geomdl as well, but alas.
I have managed to install GH Python Remote and have been using it for the last 2 months for some projects. I solved the problem @maartjehoogeveen appears to be having by not closing the console window that automatically opens when the toggle is set to TRUE. A quick check for me to see if everything is working as it should is checking if the final line of the output reads “INFO: ghpythonremote.GH_to_python:GH to python connection is OPEN”
I got this “Runtime error (Exception): No module named matplotlib” when trying to add the matplotlib to the import modules.
If I remove it from the panel, then everything is fine.
Switching the toggle on or off, didn’t make any difference.
This probably means you installed matplotlib in your base installation of python (the first one that shows up in your system’s path, find out which with where python).
To install in the conda virtual environment “rhinoremote”, you need to run conda activate rhinoremote before pip install matlplotlib. This needs to be run once in any new command window you open. The current conda environment name will show up in your prompt line like (rhinoremote) C:\Users\toons\>.
I had tried the anaconda prompt before, but I didn’t run the conda activate rhinoremote command first.
Makes sense now.
Hopefully last question for a while.
Since it’s such a hurdle to get these libraries to work inside Grasshopper (it’s not that bad if you know how of course), is it possible to compile your developed script into a plug-in without having to run GhPython Remote? Or is that not possible due to those libraries.
For example, say I wrote some code using the SciPy library and want to compile this. (I have read the brilliant piece of Giulio Piacentino about compiling a Python script into a plug-in)
As you can tell, I’m really only discovering GhPython just now.
I have recently developed a C# plug-in, but I’m just browsing options for more advanced programming using other libraries and packages…
I’d say maybe, but you will still need to install GH Python Remote where the components are used, so very probably not what you were hoping for.
What could be compiled into a GH component here: the GH Python Remote user object itself, the GH Python scripts that use it, or both at the same time into one thing.
Compiling the GH Python Remote user object, you would still need to install a CPython distribution and the gh-python-remote pypi package on CPython and IronPython. So I don’t think it would make anything easier. Also, that’s provided the compilation can properly deal with the sticky dict and non-standard libraries.
You can distribute GH Python scripts as user objects or compiled components, even if they require GH Python Remote. Again, GH Python Remote installation required. Compiling might help you gain some speed against a user object but not for the parts that call CPython.
Compiling both GH Python Remote and additional GH Python scripts into one component feels like a recipe for disaster, as having several of them interact on the same GH canvas would be pretty difficult.
This thread has not been really focused on a clear direction, so I’m just gonna half-hijack again: I just released a new version of GH Python Remote which resolves the timeout issue.
You can now have calls to the remote python that take longer than 30 seconds to complete! That works for matplotlib plots, but also any long running thing like a simulation. I thought some of you here might be interested to know about it.
To install, the commands are almost the same as usual, just dropping the --no-binary option:
Hello,
I am importing firebase_admin module using GHPython remote. Then I’m using the firebase_admin= scriptcontext.sticky['firebase_admin'] sticky to access firestore module. But for some reason I’m getting the error below.
I successfully ran a similar python script as what I’m using here on Jupyter notebook on the same machine, and it has been able to access the firestore module. Do you know what the issue might be?
Runtime error (Exception): 'module' object has no attribute 'firestore'
Traceback:
line 102, in value, "C:\Users\Admin\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\async_.py"
line 469, in sync_request, "C:\Users\Admin\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\Admin\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\Admin\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rpyc\core\netref.py"
line 22, in script
Can you tell me what versions you have installed, by running the following commands?
In the Windows cmd:
conda activate rhinoremote
conda -V
python -V
pip show rpyc
pip show gh-python-remote
In a Rhino Python script:
import rpyc, ghpythonremote, sys, os
from ghpythonremote import version as ghpyrv
print(sys.version)
print(sys.path)
print(rpyc.__version__)
print(rpyc.__path__)
print(ghpyrv.__version__)
print(ghpythonremote.__path__)
And the version of Rhino you are using (you can find it by clicking on Help in the Rhino menu bar, then About Rhino)
PS: I edited your post to use code blocks (enclosing a block of lines in triple backticks “```”) so it is easier to read)
@rajputaman0493 Unless you are getting the same error message, what I do to help others will probably not help you. Can you post the error message you are seeing, and some context on how it happened?
C:\Users\Admin>conda activate rhinoremote
'conda' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Admin>conda -V
'conda' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Admin>python -V
Python 2.7.18
C:\Users\Admin>pip show rpyc
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Name: rpyc
Version: 4.1.5
Summary: Remote Python Call (RPyC), a transparent and symmetric RPC library
Home-page: http://rpyc.readthedocs.org
Author: Tomer Filiba
Author-email: tomerfiliba@gmail.com
License: MIT
Location: c:\python27\lib\site-packages
Requires: plumbum
Required-by: gh-python-remote
C:\Users\Admin>pip show gh-python-remote
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Name: gh-python-remote
Version: 1.4.1
Summary: GH Python Remote is a package to get Rhinoceros3D/Grasshopper and Python to collaborate better: connect an external python instance to Grasshopper, and vice-versa.
Home-page: https://github.com/Digital-Structures/ghpythonremote
Author: Pierre Cuvilliers
Author-email: pcuvil@mit.edu
License: MIT
Location: c:\python27\lib\site-packages
Requires: rpyc
Required-by:
I think the error is with the initial imports in GH Python Remote. Try adding firebase_admin.firestore to the list of imports in the “modules” input of GH Python Remote, after the firebase_admin line.
There is also an issue in the versions you have installed, but it’s probably not creating the issue. You have installed the latest version of GH Python Remote in your python installation in C:\python27 but this is not the version installed in the Rhino IronPython. Try running python -m ghpythonremote._configure_ironpython_installation 6 in the Windows command line.
thank you for all this information, it helped me get everything up and running however…
I am having trouble “Linearregression”.
I installed sklearn and sklearn.linear_model into the modules input on the GH Python Remote with success but…
I can’t get “from sklearn.linear_model import LinearRegression” run.
Any ideas about this? It might help me to get the astype() function to work in Pandas as well if I can figure out how to go deeper into the sklearn library.