-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from rmanly/troubleshoot_script
troubleshoot script from notebook Issue #1103
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
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() |