How to import from Qt:: namespase (Qt5, Python3.x)?
<p>For my application I need to set some widget parameters like alignment (<code>Qt::AlignBottom</code>) and others. But I can't import them (other PyQt5 staff imports withot any issues).</p>

<p>Using this code</p>

<pre><code>from PyQt5 import Qt

progressBar = QProgressBar(splash)
progressBar.setAlignment(Qt.AlignBottom)
</code></pre>

<p>I got following error:</p>

<pre><code>Traceback (most recent call last):
  File "run_app.py", line 50, in &lt;module&gt;
    runSemApp(sys.argv)
  File "run_app.py", line 32, in runSemApp
    progressBar.setAlignment(Qt.AlignBottom)
AttributeError: 'module' object has no attribute 'AlignBottom'
</code></pre>

<p>And using this one works:</p>

<pre><code>from PyQt5.Qt import *

progressBar = QProgressBar(splash)
progressBar.setAlignment(Qt.AlignBottom)
</code></pre>

<p>Though I have working sollution I would like to import only <code>Qt.AlignBottom</code> and not <code>*</code>. And why <code>Qt.AlignBottom</code> doesn't work with <code>from PyQt5 import Qt</code>?</p>

<p>You can do this</p>

<pre><code>&gt;&gt;&gt; from PyQt5.QtCore import Qt
&gt;&gt;&gt; Qt.AlignBottom
64
&gt;&gt;&gt;
</code></pre>

<p>You can't import <code>AlignBottom</code> only because QtCore is not a package itself, it's just a module on it's own (a single file). it's important to know that <strong>all packages are modules, but not all modules are packages</strong></p>

<p>so this won't work</p>

<pre><code>import PyQt5.QtCore.Qt

ImportError: No module named 'PyQt5.QtCore.Qt'; 'PyQt5.QtCore' is not a package
&gt;&gt;&gt; import PyQt5.QtCore
&gt;&gt;&gt; QtCore
&lt;module 'PyQt5.QtCore' from '/usr/lib/python3.5/site-packages/PyQt5/QtCore.so'&gt;
&gt;&gt;&gt; import PyQt5
&gt;&gt;&gt; PyQt5
&lt;module 'PyQt5' from '/usr/lib/python3.5/site-packages/PyQt5/__init__.py'&gt;
&gt;&gt;&gt;
</code></pre>

<p>Looking at the output you can see that <code>QtCore</code> is a single file which contains a class <code>Qt</code> that contains other classes and methods on which <code>AlignBottom</code> is part of, you can see that with.</p>

<pre><code>&gt;&gt;&gt; from PyQt5.QtCore import Qt
&gt;&gt;&gt; help(Qt)
</code></pre>

<p>On the otherhand PyQt5 is a package (folder containing other modules) points to it's <code>__init__.py</code></p>

<p>i'll suggest you read the <a href="https://docs.python.org/3/tutorial/modules.html" rel="nofollow">docs</a> on Modules and this <a href="http://stackoverflow.com/questions/7948494/whats-the-difference-between-a-python-module-and-a-python-package">SO</a> question</p>

python qt python-3.x pyqt5