擅长:python、mysql、java
<p>您正在python3项目中尝试python2样式的相对导入:<code>import constants</code>将在python3中尝试导入<code>constants</code>系统路径水平。在</p>
<p>相反,使用类似</p>
<pre><code>from . import constants
</code></pre>
<p>在主.py在</p>
<p>请参见示例<a href="https://www.python.org/dev/peps/pep-0404/#imports" rel="nofollow noreferrer">PEP 404</a>:</p>
<blockquote>
<p>In Python 3, implicit relative imports within packages are no longer
available - only absolute imports and explicit relative imports are
supported.</p>
</blockquote>
<p>和<a href="https://stackoverflow.com/questions/12172791/changes-in-import-statement-python3">this SO question</a>。在</p>