I'm missing something about package structure – can't run in-place

After a bit of directory reshuffling, I’m having trouble running my test suite in place. I get this error:

ModuleNotFoundError: No module named 'polly.reader'; 'polly' is not a package

My directory structure is:

.
./polly
./polly/__init__.py
./polly/polly.py
./polly/reader.py

I’m running like this:

python polly/polly.py ...

where python is a Conda version of Python 3.12.

polly.py imports the reader module like so:

from polly.reader import Reader, smart_open, LOG_FORMAT

This all works when installed. The directory structure in the wheel generated using python -m build looks the same to my eye.

% unzip -t dist/polly-1.0-py3-none-any.whl 
Archive:  dist/polly-1.0-py3-none-any.whl
    testing: polly/__init__.py        OK
    testing: polly/polly.py           OK
    testing: polly/reader.py          OK
    testing: polly-1.0.dist-info/LICENSE   OK
    testing: polly-1.0.dist-info/METADATA   OK
    testing: polly-1.0.dist-info/WHEEL   OK
    testing: polly-1.0.dist-info/entry_points.txt   OK
    testing: polly-1.0.dist-info/RECORD   OK
No errors detected in compressed data of dist/polly-1.0-py3-none-any.whl.

I just can’t run from my git checkout. I must be missing something obvious, but what?

I think you want

python -m polly.polly
2 Likes

Ah, thanks, that did the trick!