Jump to content

Accessing Packaged Python Modules


geneome

Recommended Posts

I want to bring in a python module into Houdini. This module is set up with multiple folders with various files (a package) so that I can import them like

import myCoolModule.thisFolder as X

or

import myCoolModule.thatFolder as Y

The HOM docs state:

A good way of running your Python code is to import it as a module. Houdini will automatically append all the directories in $HOUDINI_SCRIPT_PATH named scripts/python to sys.path. So, if the module is in $HOME/houdini9.0/scripts/python/yourmodule.py, you can run import yourmodule. If the path to the file is not already in sys.path, you
Link to comment
Share on other sites

I want to bring in a python module into Houdini. This module is set up with multiple folders with various files (a package) so that I can import them like

import myCoolModule.thisFolder as X

or

import myCoolModule.thatFolder as Y

The HOM docs state:

This seems to mean if you have one .py file, since when I try to add folder structures to MyPath\Houdini X.X.X\scripts\python Houdini doesn't see anything in the folders and an error is returned saying the module doesn't exist when I run a script in the script sop importing the module. Putting this module in the MyPath\Houdini X.X.X\python\libs folder doesn't give me an error that the module is missing. Is this the right way to add these kinds of packaged modules to Houdini?

P.S. I've been testing this on Windows using Houdini 10.0.227.

1. To turn a folder into Python's package you need to create __init__.py file inside it. There could a couple of import statements in it, if you'd like to have the rest of files in the same name space.

2. Personally I'm happy with ($HSITE or )$HOME/houdinix.x/scripts/python/here_modules scenario. My setup that works:

./python/pythonrc.py

./python/some_utils.py (imported into pythonrc.py)

./python/module1/__init__.py (with some imports into main space 'from ... import *)'

./python/module1/module1.py (some very special classes etc)

./python/module2/__init__.py

./python/module2/submodule/__init__.py

./python/module2/submodule/submodule.py (some even more special classes etc)

This implies of course that the modules are Houdini specific. If you want to work with generic modules absent in distribution, PYTHON_PATH is the way to go I suppose.

hope this helps,

skk.

PS I haven't check H10 on Windows box (missing one). But in H9/9.5 it works like this. The way Houdini works with Python on Windows is a kind of pita, but I think there was no other way for SESI to do that. If I need some module I install it in standard location (C:Python2.5/libs/site-packages) and simple copy a whole folders to $HSITE.

Edited by SYmek
Link to comment
Share on other sites

This implies of course that the modules are Houdini specific. If you want to work with generic modules absent in distribution, PYTHON_PATH is the way to go I suppose.

This helps a great deal. They are generic modules so it seems that placing them in PYTHON_PATH is the way to go. Thanks SYmek!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...