Work at Google on a team that works primarily in python has pushed me
to get tons better at python. It's one thing to know and working a
language. It's a whole nother thing to get to that expert level. I
have been trying to figure out how to get others the hard won
knowledge that makes for amazing python. The is always the danger of
getting overly clever and writing code that is difficult to
understand. Writing and managing python packages is an area that I
have felt like was too difficult. I finally feel like I am starting
to break through some of the confusion. This might not be the right
thing in the long run with python 3 working on a new distribution
package, but with the advent of the distribute package
(a fork of setuptools), I'm
feeling more comfortable.
I few years ago, I discovered the python module yolk (https://github.com/cakebread/yolk). This is a nice module that makes it easy to ask questions about your python install from the command line.
I few years ago, I discovered the python module yolk (https://github.com/cakebread/yolk). This is a nice module that makes it easy to ask questions about your python install from the command line.
virtualenv test-ve source test-ve/bin/activate pip install yolk yolk --list Python - 2.7.3 - active development (/sw/lib/python2.7/lib-dynload) pip - 1.2.1 - active setuptools - 0.6c11 - active wsgiref - 0.1.2 - active development (/sw/lib/python2.7) yolk - 0.4.3 - active # "yolk -U" or yolk --show-updates No newer packages found at The Cheese ShopGoing back to my normal python environment, you can see a list of packages that are out of date:
yolk -U | head Cython 0.16 (0.18) Pygments 1.5 (1.6) SQLAlchemy 0.7.9 (0.7.10) Shapely 1.2.16 (1.2.17) distribute 0.6.34 (0.6.35) docutils 0.8 (0.10) logilab-common 0.58.3 (0.59.0) Mercurial 2.4.2 (2.5.1) mock 0.7.0b3 (1.0.1) numexpr 1.4.2 (2.0.1)That's nice, but I've blogged about yolk before and it would be better to know how to do this kind of thing from within python. What if I want to list which packages I have installed from within an IPython notebook to document the state of the world that I used? I'd like the names of all python modules as found in pypi and the versions of a few critical packages.
deactivate # drop out of test-ve virtualenv --system-site-packages test2-ve source test2-ve/bin/activate pip install bigquery # This is Google's BigQuery python interface. ipython notebook --pylab=inlineAnd now, how do I ask about packages in the notebook?
import pkg_resources pkgs = [pkg for pkg in pkg_resources.Environment()] len(pkgs) pkgs[:10] ['configobj', 'logilab-astng', 'shapely', 'pyproj', 'distribute', 'yolk', 'python-dateutil', 'pygments', 'mysql-python', 'numexpr'] bq_version = pkg_resources.get_distribution('bigquery').version bq_version '2.0.12' pkg_resources.parse_version(version) ('00000002', '00000000', '00000012', '*final')So, I'm using version 2.0.12 of the BigQuery python module.