Jump to content

Run Python with system environment variables


fubbu

Recommended Posts

Can i open from houdini python shell a system python with all data from it.

When i try open C:/Python27/python.exe from houdini python shell it always override system environment to houdini environment.

And i also must say i cant add system python path because it always run houdini python library first and i always get an error, i try write PYTHONHOME and all environments from help

https://www.sidefx.com/docs/houdini/ref/env.html, and nothing works.(Why i need that because i run external program by subprocces and it need system enviroment to run correctly)

Could some help?

pythonProblem.jpg

Link to comment
Share on other sites

Ok i found one thing. When i run houdini all commands are runing from hython not python now question is the same how run command from python (even this python in orginal houdini folder "C:\Program Files\Side Effects Software\Houdini 17.5.258\python27") because script only dont work in hython.

Link to comment
Share on other sites

Hi Daniel,

Interesting question, I have never tried relinking the default python libs! The wiki says it's not possible on windows (See the picture below).

Maybe you can get the original host env like described in this StackOverflow Post: https://stackoverflow.com/questions/23728250/start-new-subprocess-with-default-environment-variables

import subprocess
try:
    import _winreg as winreg
except ImportError:
    try:
        import winreg
    except ImportError:
        winreg = None

def env_keys(user=True):
    if user:
        root = winreg.HKEY_CURRENT_USER
        subkey = "Environment"
    else:
        root = winreg.HKEY_LOCAL_MACHINE
        subkey = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
    return root, subkey

def get_env(name, user=True):
    root, subkey = env_keys(user)
    key = winreg.OpenKey(root, subkey, 0, winreg.KEY_READ)
    try:
        value, _ = winreg.QueryValueEx(key, name)
    except WindowsError:
        return ""
    value = winreg.ExpandEnvironmentStrings(value)
    return value

env_PATH = get_env("PATH", False)
### Check If ENV changes work
subprocess.Popen(["echo" ,"%PATH%"],env={"PATH":str(env_PATH)},shell=True)

### Start File With Original ENV
subprocess.Popen(["S:/python_2.7.5/python.exe" ,"S:/print_sys_path.py"],env={"PATH":str(env_PATH)},shell=True)

 

OverrideEnvWindowsOnly.jpg

Edited by LucaScheller
Link to comment
Share on other sites

Thx Luca for answere but it didnt work it always run from hython. But now i try something else. When i run houdini shell(not python shell) and I run virtual enviroment (which i create before) and then run python everything is ok. Hython is overrided and my scripts work. Everything starts working like in regular python. Now i try write script that will by run this virtual enviroment and run my scripts. If it will succeed i post solve here.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...