Make pythonrc.py be recognized by any Python version

   1169   3   1
User Avatar
Member
109 posts
Joined: Aug. 2017
Offline
The docs mention that pythonrc.pywill be automatically executed if placed in pythonX.Ylibs/ folder (source [www.sidefx.com]).

The massive downside for this approach is that if I have the exact same pythonrc.pyfor multiple houdini versions that use different python versions, I now need to make multiple pythonX.Ylibs folders with identical copies of the script.

Is there any way to make Houdini recognize it and execute it from a custom folder? I tried adding my package folder to $PYTHONPATH, as well as the scripts folder without success.
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
The docs are incorrect (or outdated)!

You can place pythonrc.py, ready.py and uiready.py in the more generic HOUDINI_PATH/scripts/python/ locations and they will be executed.

For example, I have a generic $HOME/houdini directory added to my HOUDINI_PATH
$ houdini
Executing pythonrc.py in ~/houdini/scripts/python
I'm ready!!!! ready.py in ~/houdini/scripts/python
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
As a followup, what the docs also don't mention is that unless you really do have a need for different files for different Python versions, the only other real usecase for putting things in pythonX.Ylibs folders is that it's the only way you can currently override shipped Houdini modules in the $HH/pythonX.Ylibs folder.

Because of how Houdini sets up sys.path at startup time, $HH/pythonX.Ylibs will always come BEFORE any $HOUDINI_PATH/scripts/python entries, but AFTER any $HOUDINI_PATH/pythonX.Ylibs locations. This means that if you need to override anything in $HH/pythonX.Ylibs, you need to have your overridding modules in a pythonX.Ylibs folder.

I've definitely been guity of this too in the past until figuring it out and I generally put all my stuff under scripts/python now, expect when needing the specific overridding behavior such as using a custom nodegraphhooks.py to add network editor events
Edited by graham - Feb. 4, 2025 09:08:43
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
109 posts
Joined: Aug. 2017
Offline
It works! Thank you Graham, that is a lot of amazing info.

I now see that the docs do mention this path one time, but it's very easy to miss.
  • Quick Links