Pip has really made management of packages in a Python installation much less frustation free, though some glitches/annoyances remain. One issue I’ve found is that it is actually a little complicated to install packages modules systemwide for all users. This is the opposite of the situation in life before Pip, where it could be incredibly painful to not have system-level privileges and use global/systemwide targets when installing packages. Definitely progress, as the the “local user ecosystem” target is definitely a more useful and more common objective.
When running “pip” to install a package from a local file system, do you get messages like “Found existing installation package_name”, “Not uninstalling package_name”, “Can’t uninstall ‘package_name’“, “No files were found to uninstall”? This could be because you are trying to install the package from within the package root directory, and “pip” is confusing the (ephemeral/coincidental) package availability from the current working directory with the package being installed and available globally.
TL;DR: Just look at the Gist. Summary: Act I, in which I try and fail. Act II, in which I think I succeed but actually failed without knowing it till I tried to use it. Act III, in which I return to my beginning, ponder the universe, dive deep into the depths of the abyss, and come back with the magic bean that makes everything work.
It is better than a nightmare from which you cannot wake up … Install Homebrew: $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" Find problems and fix them (typically resulting from Homebrew becoming very stroppy if it does not have exclusive access to “/usr/local”): $ brew doctor VERY IMPORTANT NOTE: Make ABSOLUTELY sure that the DYLD_LIBRARY_PATH environmental variable is NOT set. Having this set will cause all sorts of problems as conflicts arise between libraries that homebrew installs that some of your other packages need (e.
All the basic examples for Python’s timeit module show strings being executed. This lead to, in my opinion, somewhat convoluted code such as: #! /usr/bin/env python import timeit def f(): pass if __name__ == "__main__": timer = timeit.Timer("__main__.f()", "import __main__") result = timer.repeat(repeat=100, number=100000) print("".format(min(result))) For some reason, the fact that you can call a function directly is only (again, in my opinion) obscurely documented. But this makes things so much cleaner:
The following example shows how easy it can be to use the three interoperability modules provided by the DendroPy Phylogenetic Computing Library to download nucleotide sequences from GenBank, align them using MUSCLE, and estimate a maximum-likelihood tree using RAxML. The automatic label composition option of the DendroPy genbank module creates practical taxon labels out the original data. We also pass in additional arguments to RAxML to request that the tree search be carried out 250 times (['-N', '250']).
While Python comes with many “batteries included”, many others are not. Luckily, thanks to generosity and hard work of various members of the Python community, there are a number of third-party implementations to fill in this gap. For example, Fisher’s exact test is not part of the standard library. While Python comes with many “batteries included”, many others are not. Luckily, thanks to generosity and hard work of various members of the Python community, there are a number of third-party implementations to fill in this gap.
The pyPDF package provides really nice facilities for PDF document manipulation. Here is a simple application script to extract a specified subset of pages from a PDF file. [gist id=2189062 file=extract-pdf-pages.py]
UPDATE Nov 7, 2009: Better parsing of traceback. UPDATE Nov 4, 2009: Now passing a “-b” flag to the script opens the parsed stack frame references in a BBEdit results browser, inspired by an AppleScript script by Marc Liyanage. When things go wrong in a Python script, the interpreter dumps a stack trace, which looks something like this: $ python y.py Calling f1 ... Traceback (most recent call last): File "y.
Given a list of strings, how would you iterpolate a multi-character string in front of each element? For example, given: >>> k = ['the quick', 'brown fox', 'jumps over', 'the lazy', 'dog'] The objective is to get: ['-c', 'the quick', '-c', 'brown fox', '-c', 'jumps over', '-c', 'the lazy', '-c', 'dog'] Of course, the naive solution would be to compose a new list by iterate over the original list: >>> result =  >>> for i in k: .