How to install the Python Image Library in Houdini's Python?

   19633   9   1
User Avatar
Member
66 posts
Joined:
Offline
Hi,
I'm just starting to learn python and there's something specific I'd like to do. I want to be able to read the dimensions of an image and create a grid in Houdini of the same proportions.

I have found this info already:

If you have PIL installed
(http://www.pythonware.com/products/pil/index.htm), [pythonware.com] you can just do:
>>> from PIL import Image
>>> img = Image.open('icon.jpg')
>>> img.size
(66, 81)

Is it possible to install things like the python image library in the python distributed with Houdini? I tried to install it but it doesn't recognize Houdini's python as a valid target for installation.

If there is another way to read the dimensions of an image on disk in Houdini, I'm open to alternative solutions as well. Thanks!

Edit: I'm on Winxp64, and apparently the PIL (python image library) hasn't been ported to 64 bit python for 2.5. So this would explain why it's not recognizing it as a valid installation.
User Avatar
Member
1390 posts
Joined: July 2005
Offline
What I can tell you is that SESI is suggesting of using your system's native Python installation. The one that comes with Houdini is stripped down and lacks some modules.

I wasn't able to force Houdini to work like that though but perhaps this is another issue. If you can achieve it, all modules installed for system's interpreter will be available for Houdini.

But before that Houdini won't import anything because it can't see it unless you put you modules in a place houdini can find it, like: $HFS/scripts/python or (better) $HOME/scripts/python.

I just copied all needed modules from python path to the second one above and now I can import them in Houdini and hython as usual.

32bit/64bit is yet another issue of course…


hope this help,
sy.
User Avatar
Member
519 posts
Joined:
Offline
Hi Shikung,

you could try the compositor. Lay down an cop subnetwork, then a file node, load the image. When you right click on the image you see the size. Now you can just reference this node from the grid SOP with ch(“../cop2net1/file1/sizex”).
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
I had no problem importing PIL into Houdini.

What build are you running? There was a bug that was fixed that Houdini was not properly detecting the system installed python. This was only on Linux though.

Houdini 9.0.745: Fixed a bug where Houdini was sometimes using the $HFS/python distribution even though a perfectly usable python package was available in /usr.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
66 posts
Joined:
Offline
Thanks everyone, I'll try some more things after these suggestions.

I'll download and install a standalone python and do some further experimentation.

One more question, is it possible to use 32 bit python in 64 bit Houdini on win xp 64?

Should I instead use 32 bit Houdini if I need to use 32 bit python?
User Avatar
Member
63 posts
Joined: July 2005
Offline
To confirm: the system Python installation is not used on Win32. On my system the Python library (python25) and executable (python) are within %PATH% - yet they are not picked up (if that's the mechanism to pick them). Also I scanned the registry and the keys regarding the existence of Python are present. I posted a while back on this (http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=9716&highlight= [sidefx.com]).
User Avatar
Member
66 posts
Joined:
Offline
I have also been unsuccessful at having either 32 bit or 64 bit Houdini recognize the system 32 bit or 64 bit python. I've tried a few combinations and none of it has worked. This is on Win 64 using the latest Houdini Builds.
User Avatar
Staff
1256 posts
Joined: July 2005
Offline
SYmek
What I can tell you is that SESI is suggesting of using your system's native Python installation. The one that comes with Houdini is stripped down and lacks some modules.

Hi All,

Just to clariy…
On Linux, we recommend using the system's native python version. Houdini and hython are set up to work seamlessly either with the python package installed in $HFS or in /usr (or whereever else your system might install it). Python modules installed by the OS' package manager are suppose to work ‘out-of-the-box’ with the system's python distro and hence with Houdini/hython.

On Windows, however, we cannot rely on the system's python distro (which is usually installed in CPython25). The problem is that we are not guaranteed that the MSVC compiler used to build CPython25 is the same version as the one to build Houdini/hython. This is more apparent on Win64 machines where Houdini is built with MSVC2005 while python, I believe, is built using MSVC2003 by default. So on Windows, Houdini ALWAYS uses the python that's installed in $HFS.

SYmek
But before that Houdini won't import anything because it can't see it unless you put you modules in a place houdini can find it, like: $HFS/scripts/python or (better) $HOME/scripts/python.

This is a great suggestion. You can put your python modules in $HOME/houdiniX.X/scripts/python and Houdini/hython will definitely find them. As an added note, you can also modify the HOUDINI_SCRIPT_PATH environment variable so that Houdini searches other directories for python scripts.

For example, if you add “Csome_path/scripts” to HOUDINI_SCRIPT_PATH, Houdini will be able to find python modules in Csome_path/scripts/python.

One caveat to all of this is that when installing python modules on Windows, any compiled extensions (i.e. *.dll or *.pyd files) must be built with the same compiler used to build Houdini (as mentioned above). For win32, we use MSVC2003 and for win64, we use MSVC2005.

I hope this helps.

–Rob
User Avatar
Staff
1256 posts
Joined: July 2005
Offline
shikung444
I have also been unsuccessful at having either 32 bit or 64 bit Houdini recognize the system 32 bit or 64 bit python. I've tried a few combinations and none of it has worked. This is on Win 64 using the latest Houdini Builds.

Hi,

As I previously mentioned, Houdini will not use the system python on Windows. You can follow SYmek's suggestion about installing modules into $HOME/houdiniX.X/scripts/python or by editing $HOUDINI_SCRIPT_PATH.

Anyway, one of the developers from the office here successfully installed PIL on win64 and imported it in hython. Here are the steps he followed:
1. Install a win32 version of Houdini. You need a win32 build because the PIL modules are 32-bit.
2. In order to install PIL in $HFS, you need to register hython as a valid python distribution. To do this, follow the instructions from this web page:
http://effbot.org/zone/python-register.htm [effbot.org]
At this point, I have to warn you that the above link is not from Side Effects and so you should use it at your own risk. I can tell you that it worked for the developer at our office, but I cannot guarantee you anything past that.

Anyway, to register hython, you need to copy the script from that web page and paste it into its own .py file, say register_hython.py. Then from the command line, run “hython register_hython.py”
3. Run the PIL installer. hython should now be listed as one of the available python core distros. Choose it from the list and finish the installation. The installer will place the PIL files into $HFS/python/lib/python2.5/site-packages/PIL.
4. So now if you open hython, you can import any of the PIL modules.

Note that since PIL is installed into $HFS, you will need to follow the above steps everytime you upgrade or move to a different Houdini build.

Good luck!

–Rob
User Avatar
Member
63 posts
Joined: July 2005
Offline
IMHO, the problem on Windows is not so much about the external libraries (which are almost easy to include by modifying sys.path, etc) but by the older release of the python distribution. As I pointed out in a previous post, it is version 2.5 (which was quite buggy, as far as I can remember), and not the current release (2.5.1). Can something be done about that on Windows32?
  • Quick Links