Python's import situation has driven me to the brink of imsanity

Sivan Greenberg sivan at
Sun Feb 7 06:43:50 EST 2016

in sake of providing another example, as I ran into the same problem and
fixed it the very same way, one can also take a look at:
(this is the main executable)

Note the explicit imports in lines 19-22 to allow the executable finding
modules within the OS instance's site-packages structure.

Here's is Navistore's for reference (I actually use this project
as a study project in a Python course for programmers I'm running):

You may find this to be helpful:

To make Navistore's main executable be avail at command line I used this:

On Sun, Feb 7, 2016 at 8:34 AM, Kevin Conway <kevinjacobconway at>

> > My question is: is this crazy? Please tell me there's a better way and I
> just wasted my time creating this package.
> There is a better way and you have wasted your time creating this package.
> I hear your problem statement as asking two questions. The first is: What
> is the right way to include executable content in my Python project? The
> second is: How do I expose executable content from a Python project?
> As to the first question, from your project README:
> > Say you have a python project (not a package), with the following
> structure:
> All Python code that you want to install and make available in any form,
> import or executable, _must_ be contained within a Python package.
> Organizing Python code in any way other than Python packages will result in
> the challenges you have described. The correct way to include executable
> content is to place the Python code within the package structure. It should
> not be put in other directories within the repository root.
> As to the second question, once all Python code is contained within a
> package that can be installed you can use setuptools entry points to expose
> the executable code. The setup() function from setuptools that is used to
> create files has an argument called 'entry_points' that allows you
> to expose executable content over the command line. See [1] and [2] for
> more details.
> Feel free to reach out to me off-list if you have a specific project you
> need advice on. The rules for organizing and packaging Python code aren't
> complex but they tend to cause new Python developers to stumble at first. A
> general rule I give everyone when talking about packaging or importing
> code: If you have to modify sys.path to makes something work then you have
> most certainly made a mistake.
> [1]
> [2]
> On Sat, Feb 6, 2016 at 8:54 PM Chris Angelico <rosuav at> wrote:
> > On Sun, Feb 7, 2016 at 1:47 PM,  <dimva13 at> wrote:
> > > Imsanity allows you to make imports usable (not ideal, but at least
> > usable) for python projects without having to manage PYTHONPATHs or do
> > whacky stuff like running files with python -m or put even whackier
> > boilerplate at the top of every file. And all it requires is 'import
> > imsanity' at the top of every file. You can put it in a macro or even
> just
> > type it because it's short and easy to remember.
> > >
> > > My question is: is this crazy? Please tell me there's a better way and
> I
> > just wasted my time creating this package. There's nothing I'd like to
> hear
> > more.
> >
> > Well, anything that makes you type "import imsanity" at the top of
> > every script MUST be crazy. :) I don't know about the actual
> > content/purpose though. Good luck with it!
> >
> > ChrisA
> > --
> >
> >
> --

Sivan Greenberg
Co founder & CTO
Vitakka Consulting

More information about the Python-list mailing list