How to pass a .py script to hython?

   2676   5   0
User Avatar
Member
13 posts
Joined: Jan. 2023
Offline
Hi guys,
I have a test .py module with a simple print line and I've been trying to run it in command line through hython.exe.

in hython I've tried: (though it's like writing "python 'somescript.py'" in python shell I assume, won't work, no?)
hython "C:/Users/<myusername>/Desktop/script_to_run_in_hython.py"
(invalid syntax on the last ")

in powershell:
"C:/Program Files/Side Effects Software/Houdini 19.5.569/bin/hython.exe" "C:/Users/TEMP.KATANA.000/Desktop/houdini_server/script_to_run_in_hython.py"
(UnexpectedToken error)

What's the right way to run a script from hython?
Edited by KatanaPoland - July 19, 2023 09:20:17
User Avatar
Member
1922 posts
Joined: Nov. 2006
Offline
I think you'll need to provide an example of the file you're trying to run as Houdini on Windows seems to have no issues executing a passed in script for me.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Staff
31 posts
Joined: June 2018
Offline
I usually define a function in my .py file and put the code I want to run in that function. Then I do the following:

1. Start hython
2. soure my_module
3. my_module.my_function()

When I'm on Linux I use the shell. On windows I use cygwin for my shell. I've not tried this with the power shell
User Avatar
Member
3 posts
Joined: July 2023
Offline
Hello

The right way to run a Python script from hython.exe in the command line is:


hython path_to_your_script.py

Make sure to replace path_to_your_script.py with the actual path to your Python script.
User Avatar
Member
621 posts
Joined: Aug. 2008
Offline
you can put hython in path environment and call
hython path_to_your_file.py
User Avatar
Member
13 posts
Joined: Jan. 2023
Offline
Thanks for your answers guys. I ended up running a .ps1 script from powershell that sets up venv, appends to python path and runs the actual .py script in which I do:

import os, sys
sys.path.append("C:\\Program Files\\Side Effects Software\\Houdini 19.5.569\\houdini\\python3.9libs")
os.add_dll_directory("C:\\Program Files\\Side Effects Software\\Houdini 19.5.569\\bin")
import hou

Then I have access to the hou module no problem.
  • Quick Links