Difference between $PATH, sys.path and os.environ

前端 未结 2 1056
误落风尘
误落风尘 2021-01-11 20:05

What is the difference between $PATH variable, sys.path and os.environ? I understand that they both serve as paths where python searches packages. But it\'d be nice to have

2条回答
  •  一整个雨季
    2021-01-11 20:45

    sys.path

    Is a list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

    os.environ

    Is a mapping object representing the string environment. For example, environ['HOME'] is the pathname of your home directory (on some platforms), and is equivalent to getenv("HOME") in C.

    Environment variable PATH

    Specifies a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

提交回复
热议问题