pythonbashfilesystemssys

sys.path vs. $PATH in Python


In a Python program, I would like to access the $PATH variable. My understanding so far is that sys.path gives the Python module search path, but what I want is $PATH the environment variable. Is there a way to access that from within Python?

To give a little more background, what I ultimately want to do is find out where a user has Package_X/ installed so that I can find the absolute path of an HTML file in Package_X/.
If this is a bad practice or if there is a better way to accomplish this, I would appreciate any suggestions. Thanks!


Solution

  • you can read environment variables accessing to the os.environdictionary

    import os
    
    my_path = os.environ['PATH']
    

    about searching where a Package is installed, it depends if is installed in PATH