Skip to content

Instantly share code, notes, and snippets.

@soxofaan
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxofaan/cc4986cc507cb10f962d to your computer and use it in GitHub Desktop.
Save soxofaan/cc4986cc507cb10f962d to your computer and use it in GitHub Desktop.
python version dump snippet
"""
Snippet to list Python installation/packaging related version information.
Execute it with the Python executable you want to inspect.
Usage example with curl/wget tricks straight from this github gist
(optionally replace `python` at the end with the desired alternative):
curl -s https://gist.githubusercontent.com/soxofaan/cc4986cc507cb10f962d/raw/python-version-dump.py | python
wget -O - -q https://gist.githubusercontent.com/soxofaan/cc4986cc507cb10f962d/raw/python-version-dump.py | python
If your shell supports it (e.g. bash) you can also put `python` in front, like this:
python < <(curl -s https://gist.githubusercontent.com/soxofaan/cc4986cc507cb10f962d/raw/python-version-dump.py)
python < <(wget -O - -q https://gist.githubusercontent.com/soxofaan/cc4986cc507cb10f962d/raw/python-version-dump.py)
Example output:
sys.executable : '/usr/bin/python'
sys.version : '2.7.3 (default, Apr 20 2012, 22:39:59) \n[GCC 4.6.3]'
sys.prefix : '/usr'
sys.exec_prefix : '/usr'
re.__file__ : '/usr/lib/python2.7/re.pyc'
setuptools.__version__ : '0.6'
setuptools.__path__ : ['/usr/lib/python2.7/dist-packages/setuptools']
"""
def show(name, value):
print ('{n:30}: {v!r}'.format(n=name, v=value))
# The basics
import sys
show('sys.executable', sys.executable)
show('sys.version', sys.version)
show('sys.prefix', sys.prefix)
show('sys.exec_prefix', sys.exec_prefix)
# Something from the standard library
import re
show('re.__file__', re.__file__)
# Check some common packaging/installation related tools
try:
import setuptools
show('setuptools.__file__', setuptools.__file__)
show('setuptools.__version__', setuptools.__version__)
except:
pass
try:
import pkg_resources
show('pkg_resources.__file__', pkg_resources.__file__)
except:
pass
try:
import distribute
show('distribute.__file__', distribute.__file__)
show('distribute.__version__', distribute.__version__)
except:
pass
try:
import pip
show('pip.__file__', pip.__file__)
show('pip.__version__', pip.__version__)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment