1

I run my python project both locally in my development environment and from an installed package.

in my main.py I want to get the version from init.py:

from . import version

but I get the error:

ValueError: attempted relative import in non-package

my directory structure is as follows:

./proj1/main.py
./proj1/__init__.py

I'm running it via

 cd proj1 && ./main.py

I use the version for setup.py and within my main.py to output the version.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1blackmoon
  • 11
  • 2
  • Only when importing `proj1` does it become a package. By running `main.py` as a *top-level script* you removed that attribute; `proj1` is just another directory now, not a package. – Martijn Pieters Oct 03 '18 at 13:34

0 Answers0