[Distutils] 3.3 / packaging - support for Windows installation locations

Vinay Sajip vinay_sajip at yahoo.co.uk
Sat Jun 18 14:26:26 CEST 2011

While packaging's support for path-based installation seems reasonably
comprehensive, on recent Windows versions, installation locations aren't
always simply based on fixed or declaratively specifiable locations.

For example, say that some data needs to be installed in a user's "Documents"
folder under Windows 7. You might assume that this would be e.g.
"C:\Users\Vinay\Documents", but in fact that might not be the correct location.
To do it correctly for all scenarios involves jumping through some hoops:

from ctypes import windll, Structure, byref, w_char_p # and other stuff besides

class GUID(Structure):
    # define a GUID structure in terms of ctypes longs, shorts etc.

Documents_FolderID = GUID(...) # using constants from Windows KnownFolders.h

path = w_char_p() # to hold the resulting path

windll.shell32.SHGetKnownFolderPath(byref(Documents_FolderID), ...,
                                    byref(path), ...)

and then use path.value as the location of the Documents folder.

What's the best way of handling these sorts of situations with Python 3.3


Vinay Sajip

More information about the Distutils-SIG mailing list