Rhino 8 Script Editor Python Module Search Path missing

I am testing our python Rhino 7 packages in Rhino 8 and I wanted to try the new Script Editor. Am I missing something? The old Rhino Python Editor (IronPython) has the possibility to add module search pathes within the Tools/Options pop up menu. This is also still available in Rhino 8. Where do I find a menu in the new Script Editor to add module search pathes for IronPython (Python 2) and CPython (Python 3)?
All my python code and Rhino Python Commands are organized in python native packages. I do not want to use sys.path.append or extend to add these pathes to all the run scripts.

Ok, I found this comment in an iron python snipped.

- Use env directive to add an environment path to sys.path automatically
    # env: /path/to/your/site-packages/

It seems to work, but where does Rhino put this? This seems to be global, because I can use it in other scripts as well. Is there a configuration file that I can change afterwards?

@daniel.kowollik Hi Daniel
There are no configs at the moment. The env directive adds that to the IronPython engine (which technically runs other scripts as well so it is global currently, but not guranteed to stay like this)

I can add options in the new editor to add these default search paths if that’s what you need

Hi @eirannejad, if this is not going to stay as it has been over the last years than it potentionally will break all scripts which can be started from a button command without hardcoded paths to the script. Eg. say you have organized your workspace with buttons having this as a macro:

! _-RunPythonScript MyScriptName.py

And you have defined the path to a folder containing your scripts under Tools/Options/Search Paths, then these buttons all will not work anymore.

I often publish larger packages of uncompiled scripts with a workspace (rui) file. All the user needs to do to “install” the package is to define the Search Path to the location he extracted the package to. So i hope you will not abandon that useful concept of defining global search paths for scripts and modules.
_
c.

4 Likes

Okay I added this ticket and will get that implemented ASAP

RH-79027 Add Rhino options search paths to Python engines

1 Like

Hi, sounds great. Are you going to add this for IronPython and CPython?

It would be great to have a user specific config file (for example JSON or YAML). You can add the GUI feature like in the old Editor and one would be able to write or edit this config file with other tools as well. We usually use a hidden config file in the home directory for our toolchains.

I found out that Rhino 8 uses the Windows PYTHONPATH variable and adds the entries to the cpython search path. This setup could lead to conflicts, if one uses another system wide cpython distribution and packages that are not available in Rhino 8 or provide a different version of the identical package.

1 Like

@daniel.kowollik
Language specific module search paths coming in Rhino 8.4 RC
I’ll document this on developer docs and will share

Rhino_84I72pAQ0c

2 Likes

@eirannejad looks great. Thank you, this will help a lot.

1 Like

Hi @eirannejad ,

When will 8.4 RC be available? Like Clement did, over last decade, I’ve been relying on “Module Search Paths” functionality to create uncompiled packages. Until there is a better workaround, it would be cumbersome for many users to shift from the old workflow.

Best,
Vincent

Hi Vincent, it is already there to download if you set it like below:


_
c.

1 Like

Ok, I managed to upgrade to RC8.4. But when I do ! _-RunPythonScript Module/Script.py. It still cannot find the script in the search paths? (the path is added and rhino restarted)

Am I missing some steps? @clement

Right now you need to add the paths to the search paths in the new editor

but tomorrows 8.4 build has a few more paths automatically added to the search paths. Notably the scripts path in Rhino app data directory.

@vincentfs Where is Module/script.py located?

Hi @vincentfs, i guess it should be like this:

! _-RunPythonScript Script.py

then define the full path to Module in the searchpaths for the new script editor under

Tools > Options > IronPython 2

_
c.

Added path file to docs. Tomorrow’s 8.4 RC will include these changes

https://developer.rhino3d.com/guides/scripting/editor-configs/

My folder is structured like this:

/search/path/
* module1 folder
* - script11.py
* - script12.py
* module2 folder
* - script21.py
* - script22.py

The method I used worked very well across Rhino 5,6,7. I think this is a better workflow in terms of namespace management than putting all scripts directly under one search path. At least when you start a new module, you don’t need to add module folder to search path again.

-----edited:
I tried to put the script directly under search path, and do ! _-RunPythonScript Script.py without module folder prefix. It didn’t respond either. I’m not sure whether the method works on other computer. Or am I missing some settings for the python engine? I’m running on (8.4.24016.19001, 2024-01-16).

Another question is, for command line “RunPythonScript”, what python engine (2 vs 3) does it defaults to? Will it change depends on the hashtag line in the scripts?

Best,

Any updates or suggestions? @eirannejad
Thanks!

Hi @vincentfs,

as far as i understand, EditPythonScript and RunPythonScript use IronPython 2.7 in Rhino 8.

_
c.

Thanks @clement . I finally figured out that in order for RunPythonScript to work, I had to set the search path through EditPythonScript which is a hidden window in Rhino 8.

As a reference for anyone who is curious, by default RunPythonScript use IronPython2.7, but if you have #! python 3 in the code, it will use python 3.8.

v.

2 Likes

Python 3.9.10 to be exact