I’m having troubles importing (full) Python 2.7 library modules in GhPython.
It has been suggested multiple times on this forum to either:
put the module files directly in the path used by GhPython
sysmodule within the GhPython component :
import sys my_path = r'path\to\mymodule.py' if not my_path in sys.path: sys.path.append(my_path)
For some reason that the second option never worked for me (always leaving me on a
Runtime error (ImportException): No module named 'nameofthemodule' error), so I decided to drop the module files in one of the directory used by GhPython instead (the
IronPython folder in my case).
Unfortunately that second solution doesn’t seem to work either for me, GhPython being then unable to load correctly or entirely the library:
- sometimes GhPython gives me an
ImportExceptionwhen trying to load a method of the library
- other times the library loads but its functions/methods then fail to work
Examples with 3 python libraries, all installed with the
pip command and then placed in the
IronPython folder by hand:
–> with the noise, I get:
Runtime error (ImportException): cannot import _perlin from noise Traceback: line 12, in <module>, "C:\Program Files\IronPython 2.7\Lib\site-packages\noise\__init__.py" line 19, in script
–> with the noiselib library, I get:
Runtime error (ImportException): No module named _simplex Traceback: line 6, in <module>, "C:\Program Files\IronPython 2.7\Lib\site-packages\noiselib\__init__.py" line 19, in script
–> with opensimplex, the library loads but when instantiating the OpenSimplex() class:
Runtime error (TypeErrorException): expected signed long, got long Traceback: line 81, in overflow, "C:\Users\liukov\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\opensimplex\opensimplex.py" line 99, in __init__, "C:\Users\liukov\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\opensimplex\opensimplex.py" line 21, in script
I should indicate that every library mentionned works perfectly fine outside Grasshopper (tested with the Windows prompt command or inside a Jupyter Notebook with Python 2.7)
- Why do I keep getting these errors ? Is there something that I’m doing wrong ?
- How can I make one of these libraries work with GhPython ?
PS: This is my very first post on this forum so please forgive me if this issue doesn’t belong to this category or if my explanation if lacking clarity. Thank you