该变量的值完全由Python代码确定:
def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line option) True: Safe and enabled """ if sys.flags.no_user_site: return False if hasattr(os, "getuid") and hasattr(os, "geteuid"): # check process uid == effective uid if os.geteuid() != os.getuid(): return None if hasattr(os, "getgid") and hasattr(os, "getegid"): # check process gid == effective gid if os.getegid() != os.getgid(): return None return True
第一个测试只是针对已使用的
-s开关或
PYTHONNOUSERSITE环境变量。
None如果有效用户标识或组标识不同于进程用户标识或组标识,则剩下的测试将返回。
管理员可以设置有效用户ID或组ID位,然后将可执行文件的有效用户更改为可执行文件的所有者或组,而不是执行Python的用户,此时将返回上述函数
None。
除此之外,
sitecustomize.py软件包还可以将值设置为
None,并再次从路径中显式删除用户目录。如果是这样,则将
usercustomize.py跳过导入步骤。



