[Python-ideas] python_modules as default directory for dependencies in distutils

Jim Jewett jimjjewett at gmail.com
Wed Nov 21 23:21:36 CET 2012

On 11/21/12, Philipp Hagemeister <phihag at phihag.de> wrote:
> On 11/21/2012 04:27 AM, Nick Coghlan wrote:
>> Or install them all in a single directory, add a __main__.py file to that
>> directory and then just pass that directory name on the command line
>> instead of a script name. The directory will be added as sys.path[0] and
>> the __main__.py file will be executed as the main module

>... And wouldn't one sacrifice the ability to seamlessly import from the
> application's code itself.

Do you mean from within the application, or from the supposedly
independent libraries that you depend upon?

> As far as I understand, you suggest a setup like ...

> ./python_modules/__main__.py -> ../main.py
> ./python_modules/myapp -> ../myapp  # Or a path fixup in main

Skip those two ... if something inside python_modules is looking
at your application, then it really shouldn't be segregated into a
python_modules directory.  (And if you need to anyhow, make
those imports explicit, so that you don't end up with two copies of
the "same" module.)

That said, I think (but haven't tested) that import __main__ or
import myprojutils will do the right thing, because of sys.path[0]
being the root directory of myapp.


More information about the Python-ideas mailing list