Skip to content

Commit

Permalink
Merge pull request #72 from rmanly/troubleshoot_script
Browse files Browse the repository at this point in the history
troubleshoot script from notebook Issue #1103
  • Loading branch information
Carreau committed Feb 22, 2016
2 parents bc9678c + 846352d commit 7d71e36
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions scripts/jupyter-troubleshoot
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python
"""
display environment information that isfrequently
used to troubleshoot installations of Jupyter or IPython
"""

# import argparse
import os
import platform
import subprocess
import sys


# def get_args():
# """
# TODO: output in JSON or xml? maybe?
# """
# pass

def subs(cmd):
"""
get data from commands that we need to run outside of python
"""
try:
stdout = subprocess.check_output(cmd)
return stdout.decode('utf-8').strip()
except subprocess.CalledProcessError:
return None


def get_data():
"""
returns a dict of various user environment data
"""
env = {}
env['path'] = os.environ.get('PATH')
env['sys_path'] = sys.path
env['sys_exe'] = sys.executable
env['sys_version'] = sys.version
env['platform'] = platform.platform()
# FIXME: which on Windows?
env['which'] = subs(['which', '-a', 'jupyter'])
env['pip'] = subs(['pip', 'list'])
env['conda'] = subs(['conda', 'list'])
return env


def main():
"""
print out useful info
"""
#pylint: disable=superfluous-parens
# args = get_args()
environment_data = get_data()

print('$PATH:')
for directory in environment_data['path'].split(':'):
print('\t' + directory)

print('\n' + 'sys.path:')
for directory in environment_data['sys_path']:
print('\t' + directory)

print('\n' + 'sys.executable:')
print('\t' + environment_data['sys_exe'])

print('\n' + 'sys.version:')
if '\n' in environment_data['sys_version']:
for data in environment_data['sys_version'].split('\n'):
print('\t' + data)
else:
print('\t' + environment_data['sys_version'])

print('\n' + 'platform.platform():')
print('\t' + environment_data['platform'])

print('\n' + 'which -a jupyter:')
print('\t' + environment_data['which'])

print('\n' + 'pip list:')
for package in environment_data['pip'].split('\n'):
print('\t' + package)

print('\n' + 'conda list:')
for package in environment_data['conda'].split('\n'):
print('\t' + package)


if __name__ == '__main__':
main()

0 comments on commit 7d71e36

Please sign in to comment.