First. thanks for getting python3 going huge leap forward.
I use Anaconda quite a lot. can i not have rhino use my existing conda environments? meaning i have to double down on recreating those envs into the .rhinocode folder?
I have numpy installed into the .rhinocode env OTB from mcneel and that works to import , I purposely created and anaconda env targeting python 3.9 and installed pandas there. Here is the error i get as well as the code…
definitely something up with the pandas library and something else. I can get matplotlib to import form the conda env. which is great! so partially solved. i adjusted the locale thing as discussed in other threads and also inserted the pathing to the front of the sys.path list. I have python standalone outside of anaconda as well for nodejs packages so those were also coming up in the sys.path.
import rhinoscriptsyntax as rs
import scriptcontext as sc
name = getpass.getuser()
It seems that the approach right now is that you treat the python instance that rhino installs as it’s own environment, and install packages using the “#r : numpy, matplotlib” line toward the top. Obviously this is not ideal as we will end up with a massive python environment.
My preferred approach would be to release a package to conda/pypi that allows us to use our python environment to communicate with rhino/grasshopper - this would then be a requirement for any python environment that we set up for rhino/grasshopper to use. The other approach I’ve used is ghhops_server, but not all the Rhino.Geometry methods are exposed, so I was unable to get this to work as intended, also hops in Rhino 8 is non functional at the moment, hopefully they patch it soon.
Its a moving a target. I removed the sys.path. used conda to install the packages so they worked again and set he #env as described at the top of the script… then return to the previous version of the script with sys.path and then it worked again without having to set the #env at the top. Very odd.
<module ‘matplotlib’ from ‘C:\Users\/…/\anaconda3\envs\rhino\lib\site-packages\matplotlib\init.py’>
I can never remember which sub folder it is precisely either. Either look a little further for a sub folder called pandas with __init__.py in it (it never uses pandas.py, does it?), or open a repl session within your conda env outside Rhino and look at the output from:
This is all definitely in hack territory by the way, and assumes conda is just making venvs with some extra stuff it needs. If conda has added its own core libraries, or especially if it uses a site.py for example, libraries installed into conda envs might need to import the folders from those too, from Rhino’s Python.
I don’t know what that # env ... does exactly. Presumably just sys.path.append(…).
I’d try omitting the last path ending in numpy. And then try replacing all the # env: ...s with sys.path.append(...)s
If that doesnt work, then conda’s envs are too particular, to be able to easily import from, from normal Python processes. You’ll have to look into replicating in Rhino, the effects of conda activate your_env (or whatever the precise command is.
You know you don’t need conda just to use numpy, right?