title: ModuleNotFoundError when using setup.cfg and version accessed with attr
body: <p>I have a Python package with the following structure:</p>
  
  <pre class="lang-none prettyprint-override"><code>├── setup.cfg
  ├── setup.py
  └── src
      └── myproject
          ├── base.py
          ├── __init__.py
          └── version.py
  </code></pre>
  
  <p>In <code>setup.cfg</code>, the version is defined with <code>attr</code>:</p>
  
  <pre><code>[metadata]
  name = myproject
  version = attr: myproject.version.__version__
  </code></pre>
  
  <p>With <code>version.py</code> being simply:</p>
  
  <pre class="lang-py prettyprint-override"><code>__version__ = "1.2.3"
  </code></pre>
  
  <p>The package have dependencies listed in <code>setup.cfg</code>. On the other hand, the package's top level <code>__init__.py</code> imports some objects of the package:</p>
  
  <pre class="lang-py prettyprint-override"><code>from myproject.base import Stuff
  
  __all__ = ["Stuff"]
  </code></pre>
  
  <p>And, obviously, <code>base.py</code> imports some objects from the dependencies.</p>
  
  <p>The problem is now that if I try to use <code>python setup.py</code> when the dependencies are not installed, I have a <code>ModuleNotFoundError</code>/<code>ImportError</code>, since <code>__init__.py</code> imports objects importing these dependencies (this is very to case 6 in <a href="https://packaging.python.org/guides/single-sourcing-package-version/" rel="noreferrer">the Python documentation on managing version file</a>):</p>
  
  <pre class="lang-none prettyprint-override"><code>python setup.py --version
  Traceback (most recent call last):
  &lt;snip&gt;
  ModuleNotFoundError: No module named 'dependency_module'
  </code></pre>
  
  <p>which makes installation of the dependencies impossible. So what should be the best strategy to target the version file?</p>
  
  <p>So far, I have tried this weird exception handling approach on <code>__init__.py</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>try:
      from myproject.base import Stuff
  except ImportError:
      pass
  </code></pre>
  
  <p>Is there a better way? Or another approach?</p>