Integrating Pycharm with houdini tutorial?

   11464   17   8
User Avatar
Member
41 posts
Joined: 5月 2021
Offline
Well my hda script is getting larger and larger, and my eyesight is weaker and weaker, plus getting "in" and "out" for testing in the scene becomes really tiresome, stretching the window on hda script tab is really out of fashion (tear-able window would be so nice) so how do you integrate Pycharm? I have the latest (free) version 2021.2, Houdini 17.5.391, and Houdini python support archive (hyton interpreter I guess), what's next? Do I need something more? I did my share of digging on internet but all topics on different forums are at least five years old and with dozens of "solutions" who scare the pants off me... I tried to integrate Sublime Text 3 but after poking the houdini environment file Houdini froze on startup... no thank you...
User Avatar
Member
899 posts
Joined: 2月 2016
Offline
Hello Krieg,
Few months ago I submitted a feature request to improve the UI of the Type Properties Window. Feel free to add your name to ID#112807

Requests:
A) the Create Parameters area in the Parameters section should be collapsible.
B) A floating TAB Menu to add new parameters could serve very well, like the TAB Menu for operators in the network view.
C) In the Scripts sections, the scripts area on the left should be collapsible as well.


Point C) should help to have a larger area for coding in the hda script tab.


cheers
Edited by Andr - 2021年8月12日 14:11:43
User Avatar
Member
41 posts
Joined: 5月 2021
Offline
After a LOT of mumbo-jumbo with visual code studio I managed it to integrate with Houdini... Jesus Christ man... first download houdini plug-in((!!!) WHY THE F***K do we need a plug-in for this??!!?!) then assign VCS as external text editor, then choose houdini's version of python as interpreter, then write some MORE code in VCS to set path variables (which I didn't remember because I don't care) so you could have full integration i.e. import hou module and auto suggestion... and then FINALLY after more setting of color themes and size of fonts I can have full screen, medium font size solution with a good dark (i.e. black) background so I don't cry my eyes out...

Sorry for the language... but couldn't SideFX integrate some of these solutions with Houdini by default? At least ones who are free after all? Did I mention that I have tried to integrate SublimeText, Pycharm and one more who I didn't remember... they did not work either... and lack of instructions or tutorials is abysmal... few years old... different versions etc. etc.
Edited by kriegmesser74 - 2021年8月13日 13:31:21
User Avatar
Member
6 posts
Joined: 10月 2016
Offline
I agree Krieg. We can't write good, robust python code without at least one good IDE supported and documented for setup. I'm working in Pycharm and I never got it to autocomplete. can't seem to get any sort of hou module from the hython or python installs in houdini. No idea where to look at this point.
User Avatar
Member
7 posts
Joined: 2月 2017
Offline
Here is how I got the PyCharm integration working, including autocomplete:

  1. Go to your Python Interpreter settings (in the bottom right, or File>Settings>Project>Python Interpreter).
  2. Click the gear icon in the upper right corner to show all your interpreters.
  3. In the top left corner of the new window, click the "+" button to add a new interpreter.
  4. Pick the System Interpreter and then browse to the path of your Houdini installation that has the Python executable that you want to use (2.7 vs 3.7 for example). The path probably looks something like this: C:\Program Files\Side Effects Software\Houdini 18.x.xxx\python27\python2.7.exe.
  5. After you've pressed OK in the window, you will go back to the window with the list of interpreters. Select your new interpreter and click the 5th button from the top left to "Show paths for the selected interpreter".
  6. By default it should have some paths to libraries already. However, the specific hython libs are probably not in the list, so you need to add that by pressing the "+" in the top left corner. The path should look something like this: C:\Program Files\Side Effects Software\Houdini 18.x.xxx\houdini\python2.7libs (or 3.7libs if you want to use 3.7). These libs will give you the autocomplete functionality for the HOM classes.
  7. Last but not least, for each Houdini Python project you need to set the interpreter to this new interpreter. And in order to get the autocomplete working properly, you need to import the hou module at the start of each file where you want to use it. It is as simple as import hou, and PyCharm should recognize the module from the interpreter.

From there on, you can use the hou module the same way you would inside Houdini, for example:
import hou
hou.node("../..")
or
hou.pwd().geometry()

I hope this helps! I couldn't attach pictures because that would be quite a few pictures, so I hope that my instructions are clear enough to follow. If you need any further help, feel free to reach out to me.
Technical Animator (using KineFX) at Enliven | Social Enterprise
idsboonstra.artstation.com
User Avatar
Member
136 posts
Joined: 10月 2020
Offline
followed the steps to the letter, still no autocompletion
https://www.youtube.com/channel/UC4NQi8wpYUbR9wLolfHrZVA [www.youtube.com]
User Avatar
Member
539 posts
Joined: 8月 2019
Offline
    "python.autoComplete.extraPaths": [
"C:\\Program Files\\Side Effects Software\\Houdini 19.0.455\\houdini\\python3.7libs",
],
"python.analysis.extraPaths": [
"C:\\Program Files\\Side Effects Software\\Houdini 19.0.455\\houdini\\python3.7libs",
],

This is how to setup autocompletion for VScode. If you put your Python code in a package, just add them as well.

Note that VSCode doesn't do type inference, and SideFx hasn't written any type annotation in their Python. So the autocompletion is rather limited.
User Avatar
Member
5 posts
Joined: 12月 2017
Offline
hou works but Autocomplete is what is needed.
Not working....
User Avatar
Member
136 posts
Joined: 10月 2020
Offline
Ids
Here is how I got the PyCharm integration working, including autocomplete:

  1. Go to your Python Interpreter settings (in the bottom right, or File>Settings>Project>Python Interpreter).
  2. Click the gear icon in the upper right corner to show all your interpreters.
  3. In the top left corner of the new window, click the "+" button to add a new interpreter.
  4. Pick the System Interpreter and then browse to the path of your Houdini installation that has the Python executable that you want to use (2.7 vs 3.7 for example). The path probably looks something like this: C:\Program Files\Side Effects Software\Houdini 18.x.xxx\python27\python2.7.exe.
  5. After you've pressed OK in the window, you will go back to the window with the list of interpreters. Select your new interpreter and click the 5th button from the top left to "Show paths for the selected interpreter".
  6. By default it should have some paths to libraries already. However, the specific hython libs are probably not in the list, so you need to add that by pressing the "+" in the top left corner. The path should look something like this: C:\Program Files\Side Effects Software\Houdini 18.x.xxx\houdini\python2.7libs (or 3.7libs if you want to use 3.7). These libs will give you the autocomplete functionality for the HOM classes.
  7. Last but not least, for each Houdini Python project you need to set the interpreter to this new interpreter. And in order to get the autocomplete working properly, you need to import the hou module at the start of each file where you want to use it. It is as simple as import hou, and PyCharm should recognize the module from the interpreter.

From there on, you can use the hou module the same way you would inside Houdini, for example:
import hou
hou.node("../..")
or
hou.pwd().geometry()

I hope this helps! I couldn't attach pictures because that would be quite a few pictures, so I hope that my instructions are clear enough to follow. If you need any further help, feel free to reach out to me.


I keep getting this error

Attachments:
Screenshot_1.png (43.6 KB)

https://www.youtube.com/channel/UC4NQi8wpYUbR9wLolfHrZVA [www.youtube.com]
User Avatar
Member
94 posts
Joined: 4月 2011
Offline
Hi AhmedHindy
I had the same issue. If you are using python3.7 or more recent in Windows, it's more likely because of the way python loads dll. Before 3.7, adding the $HFS/bin folder to the path was good., but the path variable is not used anymore. Instead, you must use this:
import os
os.add_dll_directory("houdini_install/bin")
import hou

Here is the explaination:
python load dll failed [bugs.python.org]
User Avatar
Member
313 posts
Joined: 10月 2016
Offline
If you edit externally, will you get the built in help to work in your external editor? (see image)

Attachments:
Screenshot_2022-09-25_21-36-47.png (78.6 KB)

Interested in character concepts, modeling, rigging, and animation. Related tool dev with Py and VEX.
User Avatar
Member
3 posts
Joined: 4月 2021
Offline
choose a python interpreter then open vs code settings.json add:
"python.autoComplete.extraPaths": [
"C:\\Program Files\\Side Effects Software\\Houdini 19.5.435\\houdini\\python3.9libs"
],
"python.analysis.extraPaths": [
"C:\\Program Files\\Side Effects Software\\Houdini 19.5.435\\houdini\\python3.9libs"
],

it should recognize hou now. if your code still don't autocomplete it perhaps because the type is any, you should provide type hint when add a var:
import hou
obj: hou.Node = hou.node('/obj')
geo: hou.Node = obj.createNode('geo', 'my_geo')

now geo. will pop up suggestion

For Pycharm:
Edited by magicom - 2022年12月20日 10:27:31

Attachments:
Screenshot 2022-12-19 231101.png (131.0 KB)

User Avatar
Member
49 posts
Joined: 4月 2020
Offline
EDIT. I couldn't figure out how to get the autocomplete to work in the latest pycharm, but FINALLY got it working.

After I added the python3.7libs dir in the EVER SO hidden folder icon, i then had to invalidate the caches...
Edited by indigosm - 2023年10月6日 10:32:26

Attachments:
hou2.jpg (187.8 KB)

User Avatar
Member
274 posts
Joined: 3月 2011
Offline
indigosm
so in the newer pycharm, they moved stuff around in the python interpreter / project structure windows. has anyone found how you're supposed to add the hou library now?

i thought adding the python3.7libs dir to the 'project structure' and then marking the dir as 'sources' would get it to work, but nope. if i type in hou., i get no real autocompletes.

I'm using vscode and I'm quite happy (for several years now). The hou module works (somewhat) ok, since it doesn't always knows the type of instance you are referring to. Plus, we have a VEX extension for function autocompletion.
On vcs code, you should add (preferences->python->python settings) "$HFS\\houdini\\python3.9libs" on "python.analysis.extraPaths" list.

If you really need to use PyCharm, It'd probably have a similar way to add the path to the python environment.
User Avatar
Member
49 posts
Joined: 4月 2020
Offline
guilhermecasagrandi
python settings) "$HFS\\houdini\\python3.9libs" on "python.analysis.extraPaths" list.

If you really need to use PyCharm, It'd probably have a similar way to add the path to the python environment.

thanks i finally got it working. and yeah i absolutely love pycharm for everything except for one or two things like this. hah.
User Avatar
Member
274 posts
Joined: 7月 2013
Offline
Sometimes it nice to be able to literally put the IDE into the Houdini UI

More code, less clicks.
User Avatar
Member
1 posts
Joined: 6月 2016
Offline
indigosm
guilhermecasagrandi
python settings) "$HFS\\houdini\\python3.9libs" on "python.analysis.extraPaths" list.

If you really need to use PyCharm, It'd probably have a similar way to add the path to the python environment.

thanks i finally got it working. and yeah i absolutely love pycharm for everything except for one or two things like this. hah.

hey, could you please provide all steps how did you make it work? much appreciated. I am trying to set it up on H20 py3.9
User Avatar
Member
49 posts
Joined: 4月 2020
Offline
renderglitch
indigosm
guilhermecasagrandi
python settings) "$HFS\\houdini\\python3.9libs" on "python.analysis.extraPaths" list.

If you really need to use PyCharm, It'd probably have a similar way to add the path to the python environment.

thanks i finally got it working. and yeah i absolutely love pycharm for everything except for one or two things like this. hah.

hey, could you please provide all steps how did you make it work? much appreciated. I am trying to set it up on H20 py3.9



these are my personal notes with houdini/python/pycharm. hopefully they're legible. hah.


/*how to get houdini to use python3?*/
well, you need to download a python3 build. for example, on the daily builds page, theres a tab just for python 3 builds. if you dont grab one of those, youll still be in py27 (daily builds page is bookmarked in the 7pimps/houdini bookmarks)

/*how to get houdini python working with pycharm*/
1 : new project->existingInterpreter->systemInterpreter->C:\Program Files\Side Effects Software\Houdini 19.5.605\houdini\python3.7libs
2 : settings->project senBlah->python interpretor->click on path dropdown and at bottom is a SHOW ALL button
2a : in new popup click on folder icon
2b : click on + button and add this dir : C:\Program Files\Side Effects Software\Houdini 19.5.605\houdini\python3.7libs
3 : help->editcustomproperties->paste this : idea.max.intellisense.filesize=3000
4 : run File->InvalidateCaches->Restart

/*autocomplete not working properly?*/
you might have to force pycharm to know what a var is. heres two examples of it forcing the obj and geo vars to be known as nodes. thus their autocompletes work
obj: hou.Node = hou.node('/obj')
geo: hou.Node = obj.createNode('geo', 'my_geo')
geo.setName(name=test) <this auto complete now works and shows the vars of the function>

/*how to get a python external library to work*/
1 : houdini needs to know about the dir you put your library scripts in. that dir is defined in your preferences file : C:\Users\senec\Documents\houdini18.5\houdini.env. add this line : HOUDINI_PATH = Z:\7d\EnvArt\Blueprints\Houdini;& (the & is on purpose. it tells houdini to add this dir to the list of dirs it checks. not replace them all with this one dir)
2 : like how you have to create an OTL dir in there for HDAs, or a vex dir for vex functions, you need a python3.7libs dir for py functions. if the version of python changes, that dir would changes
2a : is houdini saying senFunctions doesnt exist? Its because theyve gone to a newer version of python and you must copy/paste your libs dir and give it a new name and close/restart houdini. i just had to create a new path called python3.10libs and close/restart and now my node grid snap script works again
3 : then if the file is called senFunctions.py, add 'import senFunctions' to your code.
4 : you have to type 'senFunctions.blahFunc()' to run a func. if you do 'import senFunctions as sf', then its : 'sf.blahFunc()'

/*force a py file to reload (reload py reimport py) <it's the reload() command but you have to import it in order to get it to work in py3>*/0
import senFunctions as sf
from importlib import reload
reload(sf)
sf.nodes_snapToGrid()
Edited by indigosm - 2024年4月12日 11:11:44
  • Quick Links