Python interpreter info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import os | |
import pkg_resources | |
def validate_path(path): | |
if path: | |
return path.split(os.pathsep) | |
else: | |
return None | |
def get_working_set(): | |
l = [] | |
for i in pkg_resources.working_set: | |
l.append('{} {} {}'.format(i.key, i.version, i.location)) | |
return l | |
def get_version_info(): | |
return '{}.{}.{} {} serial={}'.format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro, | |
sys.version_info.releaselevel, sys.version_info.serial) | |
def main(): | |
d = { | |
'general_info': { | |
'sys.prefix': sys.prefix, | |
'sys.executable': sys.executable, | |
'sys.version_info': get_version_info(), | |
'__file__': __file__ if '__file__' in globals() else None, | |
}, | |
'sys.path': sys.path, | |
'pkg_resources.working_set': get_working_set(), | |
'environ': { | |
'PATH': validate_path(os.getenv('PATH')), | |
'PYTHONPATH': validate_path(os.getenv('PYTHONPATH')), | |
'VIRTUAL_ENV': os.environ.get('VIRTUAL_ENV'), | |
'CONDA_PREFIX': os.environ.get('CONDA_PREFIX'), | |
'PYCHARM_HOSTED': os.environ.get('PYCHARM_HOSTED'), | |
} | |
} | |
j = json.dumps(d, indent=4) | |
print(j) | |
if __name__ == '__main__': | |
main() |
What a silly mistake, thanks for pointing that out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is
os.environ['PATH'].split(os.pathsep)
inspected twice and associated with different keys? Shouldn't the second occurrence beos.environ['PYTHONPATH'].split(os.pathsep)
? Note thatPYTHONPATH
is not always set (and usually not needed).