web-dev-qa-db-ja.com

UbuntuでPython 3のPyQt4を設定するには?

この質問はもともとaskubuntu.comで尋ねられましたが、注目されなかったので、質問する方が良いかもしれません。

私はシナプスでPyQt4をインストールしました。

Python3を使用しているため、EclipseでPyQt4のパスを構成する必要がありますが、python 2.6および2.7の下に相対ファイルとフォルダーしか見つからなかったため、python 2のPyQt4のみがシナプスにインストールされたようです。

PyQt4をPython 3およびEclipseで動作させるにはどうすればよいですか?

ありがとう。

[〜#〜] update [〜#〜]

この投稿に従って構成しようとしました: http://ubuntuforums.org/showthread.php?p=10914908#post10914908

しかし、エラーが発生することなくすべての指示に従った後、python 3.2でこのコードを実行するとエラーが発生します。

>>> import PyQt4

エラーメッセージは次のとおりです。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4

しかし、奇妙なことは、同じコードでpython 2.7にエラーが発生しないことです(マシンに2.7と3.2の両方がインストールされています)

27
Derrick Zhang

コンパイルに必要なパッケージをインストールします(これらすべてが必要かどうかわかりません):

Sudo apt install build-essential python3-dev libqt4-dev

最新のソースをダウンロードSIP sip-4.12.4.tar.gz (Linux、UNIX、MacOS/Xソース)。

それらを解凍し、ディレクトリを入力します。

vic@wic:~/Desktop/sip-4.12.4$ python3 configure.py 
This is SIP 4.12.4 for Python 3.2 on linux2.
The SIP code generator will be installed in /usr/bin.
...
Creating sip module Makefile...

vic@wic:~/Desktop/sip-4.12.4$ make
make[1]: Entering directory `/home/vic/Desktop/sip-4.12.4/sipgen'
...
make[1]: Leaving directory `/home/vic/Desktop/sip-4.12.4/siplib'

vic@wic:~/Desktop/sip-4.12.4$ Sudo make install
make[1]: Entering directory `/home/vic/Desktop/sip-4.12.4/sipgen'
...
cp -f /home/vic/Desktop/sip-4.12.4/sipdistutils.py /usr/lib/python3/dist-packages/sipdistutils.py

vic@wic:~/Desktop/sip-4.12.4$

最新のPyQtのソースをダウンロードします- PyQt-x11-gpl-4.8.5.tar.gz (Linux、UNIXソース)、インストールします:

vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ python3 configure.py 
Determining the layout of your Qt installation...
This is the GPL version of PyQt 4.8.5 (licensed under the GNU General Public License) for Python 3.2 on linux2.

Type '2' to view the GPL v2 license.
Type '3' to view the GPL v3 license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.
Do you accept the terms of the license? yes
Found the license file pyqt-gpl.sip.
Checking to see if the QtGui module should be built...
...
Checking to see if the dbus support module should be built...
The Python dbus module doesn't seem to be installed.
Qt v4.7.2 free edition is being used.
SIP 4.12.4 is being used.
The Qt header files are in /usr/include/qt4.
...
Creating pyqtconfig.py...

vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ make
make[1]: Entering directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/qpy'
...
make[1]: Leaving directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/designer'

vic@wic:~/Desktop/PyQt-x11-gpl-4.8.5$ Sudo make install
make[1]: Entering directory `/home/vic/Desktop/PyQt-x11-gpl-4.8.5/qpy'
...
cp -f PyQt4.api /usr/share/qt4/qsci/api/python/PyQt4.api

注:python3の代わりにpython

30
warvariuc

python 3バージョンのPyQt4をubuntuにインストールできるはずです。ターミナルを開き、次のように入力します。

Sudo apt-get install python3-pyqt4

これにより、Qt4をソースからコンパイルする必要がなくなります。私もこれをテストしました。pyqt4はpython3で動作します。

出典:Ubuntuリポジトリでのクイック検索。

64
user133987

Ubuntuにはpython2用のpyqt4パッケージのみがあるように見えるため、python3用に別のpyqt4をコンパイルする必要があります。

各pythonのsite-packagesディレクトリーを調べることで、既にインストール済みのものを確認できます。これらのディレクトリを見つけるには、次を実行します。

python2.7 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
python3.2 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"

Pyqtが適切にインストールされている場合は、PyQt4の下にsite-packagesファイルが数十個含まれる*.soディレクトリが必要です。

おそらく、python3.2には何もありません。そのため、pyqtをインポートできません。

Python3.2用のpyqtをインストールするには、 これらの手順 に従ってください。適切なpythonを使用してビルドを構成することが非常に重要であることに注意してください:

/usr/bin/python3.2 configure.py
2
ekhumoro