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.
code below
#! python3
import rhinoscriptsyntax as rs
import scriptcontext as sc
import System
import System.Collections.Generic
import Rhino
import getpass
name = getpass.getuser()
import sys
sys.path.insert(0,r"C:\Users\{0}\anaconda3\envs\rhino\lib\site-packages".format(name))
print (sys.path)
import locale
print(locale.getlocale())
locale.setlocale(locale.LC_ALL, 'en_US')
import matplotlib
print (matplotlib)
im still having all sorts of fun stuff happening right now. matplotlib and numpy confusions too. Look like we spoke too soon on this being a partial resolution.
I get the error here now regarding matplotlib wanting numpy imported
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
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’>
totally agree , autodesk did the same stuff with dynamo and local user env’s when they released python3. Managing one source of packages is way easier at the enterprise scale IMHO.
I’m not a programmer so this maybe dumb, but I see a lot of lib/ library/ site-packages folder in my environment that I just created using mamba/ conda.
Which one should I use? Lib/ Library/ libs ?
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:
import sys
print(‘\n’.join(sys.path))
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?
@eirannejad - I can’t make any of this work, I think I have exhausted all permutation and combination. Do you have any suggestions?
@James - The default way of specifying r: package doesn’t work, because of some certificate or timeout issue.
Nevertheless, I would want the script to point to what is already available locally.