Search code examples
pythonpackaging

figure out whether python module is installed or in develop mode programmatically


I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.

This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do this for me somehow.


Solution

  • Indeed, pkg_resources will do that:

    dist = pkg_resources.get_distribution('your-app')
    if dist.precedence == pkg_resources.DEVELOP_DIST:
        # package is in development mode
        ...