Houdini and Python IDE

   15323   6   1
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
I've browsed the forum in search for an answer to my question, but I was unable to find a thread that would explain how to configure one's Python IDE to completely support HOM. I don't expect miracles, like running or debugging HOM code directly from IDE, but at least I'd like it to support full code completion.
I tried with Eclipse with PyDev and PyCharm, but all I get is a mere hou module code completion. Whenever I try to assign an object to a variable, like in:
node = hou.node('/obj/geo1/')
node.setName('someName')
I get no code completion in the second line after the dot. No list of methods whatsoever.
Also, if I try to use enums (in kwargs), I usually get “Unresolved attribute reference” warnings all over the place. Like in case of hou.stringParmType.FileReference or hou.parmNamingScheme.Base1.
It's not critical, but it hinders the development of modules.
And yes, I have followed advices from various threads and have added Houdini's soho and python2.7libs directories to my interpreter paths. To no avail.
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
I realized that I didn't actually formulate a question.
So, has anyone been able to configure his Python IDE for full code completion? Not only when it comes to hou module itself, but also for objects of classes inside this module? Or this is as far as one can get?
User Avatar
Member
181 posts
Joined: Feb. 2013
Offline
A free option that may be of interest is IPython with Houdini's remote procedure call (RPC). IPython is an interactive command-line debugger with code completion, shell integration, and dynamic help.

http://ipython.org [ipython.org]

Make sure IPython is using the same version of Python as Houdini (currently 2.7.5 in Houdini 13.0). After installing IPython, enable Houdini's remote procedure call (RPC). To do so, enter the following in a Houdini Python shell:

import hrpyc
hrpyc.start_server(use_thread=False, quiet=False)




Next, switch to an external terminal application and navigate to the Houdini library:

cd $H/houdini/python2.7libs

Next, launch IPython:

/usr/local/bin/ipython

Then import core Houdini Python modules:

import hou, hrpyc

Finally, establish a connection with the Houdini application:

connection, hou = hrpyc.import_remote_module()



Snoop around your scene file:

print hou.hipFile.name
—> buttery.hip
node = hou.node('obj/box')
node.setName('meltyBox')


And see the results in the GUI:







It's possible that this RPC approach will work with the other IDEs you've tried, too.

http://www.sidefx.com/docs/houdini13.0/hom/rpc [sidefx.com]
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Thanks Chronon.
I tried RPC with Eclipse and PyCharm. While it seems to work initially, eventually the connection is dropped with the following error on IDE's side:
Traceback (most recent call last):
File “<input>”, line 1, in <module>
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\netref.py”, line 90, in __getattribute__
return syncreq(self, consts.HANDLE_GETATTR, name)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\netref.py”, line 45, in syncreq
return conn().sync_request(handler, oid, *args)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 337, in sync_request
seq = self._send_request(handler, args)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 158, in _send_request
self._send(consts.MSG_REQUEST, seq, (handler, self._box(args)))
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 153, in _send
self._channel.send(data)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\channel.py”, line 50, in send
self.stream.write(buf)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\stream.py”, line 115, in write
count = self.sock.send(data)
File “C:\Program Files\Side Effects Software\Houdini 13.0.509\python27\lib\site-packages\rpyc\core\stream.py”, line 46, in __getattr__
raise EOFError(“stream has been closed”)
EOFError: stream has been closed

And on Houdini's side it looks like this:
Exception in thread Thread-5:
Traceback (most recent call last):
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\threading.py”, line 808, in __bootstrap_inner
self.run()
File “CPROGRA~1/SIDEEF~1/HOUDIN~1.509/houdini/python2.7libs\hou.py”, line 67520, in __threadRun
self.__run()
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\threading.py”, line 761, in run
self.__target(*self.__args, **self.__kwargs)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\utils\server.py”, line 110, in _authenticate_and_serve_client
self._serve_client(sock, credentials)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\utils\server.py”, line 127, in _serve_client
conn.serve_all()
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 312, in serve_all
self.serve(0.1)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 304, in serve
self._dispatch(data)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 274, in _dispatch
self._dispatch_request(seq, args)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 233, in _dispatch_request
self._send_reply(seq, res)
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 161, in _send_reply
self._send(consts.MSG_REPLY, seq, self._box(obj))
File “C:\PROGRA~1\SIDEEF~1\HOUDIN~1.509\python27\lib\site-packages\rpyc\core\protocol.py”, line 181, in _box
cls = getattr(obj, “__class__”, type(obj))
NameError: Unknown C global variable

However, I found a workaround for code completion in PyCharm using docstring type hints. This does not eliminate the unresolved attribute references warning when it comes to enums in kwargs, but it does show me full lists of methods available to objects.

Attachments:
type_hints_pyCharm.png (11.6 KB)

User Avatar
Member
52 posts
Joined: June 2006
Offline
However, I found a workaround for code completion in PyCharm using docstring type hints. This does not eliminate the unresolved attribute references warning when it comes to enums in kwargs, but it does show me full lists of methods available to objects.

Hi ajz3d, could you please share the steps you did to get PyCharm to work with Houdini?
User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Hi Ole.
I didn't connect PyCharm to Houdini per se, meaning that the code still needs to be executed from within Houdini, not PyCharm. Also, I'm not sure if its the best way of setting up the PyCharm IDE with Houdini, but it worked very well for me so far.
Here's what I did:

1. If you haven't already, in your %USERPROFILE%\Documents\houdini13.0 create a directory called “python2.7libs”. All modules that you put there will be accessible by Houdini. (https://www.sidefx.com/docs/houdini13.0/hom/independent) [sidefx.com]

2. In PyCharm, go to File->Settings->Project Interpreter.

3. Add new interpreter (Local) and select Python interpreter bundled with Houdini. Example:
C:\Program Files\Side Effects Software\Houdini 13.0.582\python27\python2.7.exe (or python.exe - both files are identical)

4. In the Project Interpreters window, click the Interpreter Paths icon.

5. Add paths to houdini\python2.7libs (this will allow you to import hou module) and soho libraries. Example:
C:\Program Files\Side Effects Software\Houdini 13.0.582\houdini\python2.7libs
C:\Program Files\Side Effects Software\Houdini 13.0.582\houdini\soho

6. Additionally, add the path to Python libs inside your Documents\Houdini 13.x directory. Example:
F:\Users\MyUserName\Documents\houdini13.0\python2.7libs
You can start creating PyCharm projects inside this directory. Remember that if you nest modules inside folders, you should include __init__.py file inside them. Otherwise you'll get an ImportError when trying to call such module.

For code completion inside PyCharm use docstrings.
Example:
import hou

def addParms(a, b):
“”“This function adds parameters.
:type a: hou.Parm
:type b: hou.Parm
:rtype: float
”“”
return a.eval()+b.eval()

def main():
“”“Main function.
:rtype: None
”“”
node = hou.node('/obj/').createNode('geo')
“”“:type: hou.ObjNode”“”
node.parm('tx').set(10)
node.parm('ty').set(5)
# Note, that docstring supported code completion will on work
# for the first dot in a chain instruction.
# To make it work, you'd need to use:
# tx = node.parm('tx')
# “”“:type: hou.Parm”“”
# tx.set(10) # Suggestions will show here, after the dot.
# Same thing with for loops:
# for primGroup in node.node('file1').geometry().primGroups():
# primGroup will not get any code completion suggestions.
# But it won't get any in Hython too.
print(addParms(node.parm('tx'), node.parm('ty')))
PyCharm has pretty good help chapters on this one.

However, like I already mentioned, it won't work with kwargs. So you'll be getting lots of Unresolved Attribute Reference warning markers inside PyCharm.
You can add such kwarg to a list of “Ignore References” in the File->Settings->Inspections->Unresolved References->Ignore References. Example:
hou.stringParmType.NodeReference
hou.scriptLanguage.Python
etc.
But I've never bothered to do this.

To launch the code, I use:

import some_dir.pycharm_test
reload(some_dir.pycharm_test) # Necessary to force Houdini to re-read the script
some_dir.pycharm_test.main()

Where some_dir is a path to my module.
You can use this to launch the code from shelf or even when working with an HDA. Just don't forget to embed the code (or module files) after you finish working with your HDA.

I hope I didn't forget about anything.
User Avatar
Member
52 posts
Joined: June 2006
Offline
Thank you very much for the detailed description, ajz3d. Completions does seem to work now. I do get the following error message in PyCharm (3.4.1):

Failed modules

Python 2.7.5 (C:\Program Files\Houdini14.0\python27\python2.7.exe)

- _hou
- hjson
- htext

Generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available.


It seems to not matter though.
  • Quick Links