faxingberlin Posted July 10, 2019 Share Posted July 10, 2019 Hello, I want to embed my python scripts in HDA. So, I add test.pyc file to Extra Files Tab. And I want to import this PythonModule in Scripts Tab. I try to this via hou.readFile("opdef:Sop/hdaname?test.pyc"), but this cannot read pyc binary file. Is there any way to import python module in extra file? Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted July 11, 2019 Share Posted July 11, 2019 On 2019-07-09 at 7:04 PM, faxingberlin said: Hello, I want to embed my python scripts in HDA. Just copy paste your code into a PythonModule, why do you need complicate things with embedding a pyc file? Using pyc files has some benefits, but only in certain rare circumstances. If your intent is to hide the source code...well.. is it really worth it? pyc files can be easily disassembled. If you want to confuse users so they couldn't figure out your algorithm you could use a python code obfuscator like this one: https://liftoff.github.io/pyminifier/ 1 Quote Link to comment Share on other sites More sharing options...
sanostol Posted July 11, 2019 Share Posted July 11, 2019 there are some ways to use external files. one way is to load Your script into the hda in the Scripts tab. and then You can access it with toolutils.createModuleFromSection("bar", kwargs["type"], "bar_PythonModule") you can then access the methods by pwd().hdaModule().bar.... if I remember right, stalkerx777, explained this to me some time ago, thanks again this works really well Another way is to use the python2.7libs folder in a houdini path folder or in You houdini home directory every python script stored there can be imported as a module Quote Link to comment Share on other sites More sharing options...
faxingberlin Posted July 11, 2019 Author Share Posted July 11, 2019 (edited) 8 hours ago, Stalkerx777 said: Just copy paste your code into a PythonModule, why do you need complicate things with embedding a pyc file? Using pyc files has some benefits, but only in certain rare circumstances. If your intent is to hide the source code...well.. is it really worth it? pyc files can be easily disassembled. If you want to confuse users so they couldn't figure out your algorithm you could use a python code obfuscator like this one: https://liftoff.github.io/pyminifier/ Thanks. I see the link that you attached. This is awesome too! At this time, I want to know how to execute binary files( pyc is just a example ) using hou.readFile method not to hide them. I know hou.readFile method read file as string. I cannot import and execute them from HDA extra files not only py and pyc. So, I think just execute py code from string and pyc binary code from string. I found execute pyc binary by using imp, marshal module. It works perfectly. https://mail.python.org/pipermail/chicago/2007-August/002498.html I just wanted to know if there was a way to do this. I agree with the best way is just copy code to python module in HDA. Edited July 11, 2019 by faxingberlin Quote Link to comment Share on other sites More sharing options...
faxingberlin Posted July 11, 2019 Author Share Posted July 11, 2019 1 hour ago, sanostol said: there are some ways to use external files. one way is to load Your script into the hda in the Scripts tab. and then You can access it with toolutils.createModuleFromSection("bar", kwargs["type"], "bar_PythonModule") you can then access the methods by pwd().hdaModule().bar.... if I remember right, stalkerx777, explained this to me some time ago, thanks again this works really well Another way is to use the python2.7libs folder in a houdini path folder or in You houdini home directory every python script stored there can be imported as a module This is really good to import python module from external files. But extra files in HDA can load only using hou.readFile method. Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.