PyQt5 in Windows 7

Raspberry Piでいろいろやってみて、やりたいことを簡単にするに、OS 開発言語 Widgetを考えてみた。RaspBian + Python + Qtがヒットしたので、Windowsでもその環境を準備。


・OS; RaspBian
https://www.raspberrypi.org/downloads/raspbian/
・言語:Python
https://www.python.org/downloads/windows/
GUIWidget:Qt
https://www.qt.io/download
(Google ChromだとDownloadボタンが出なかったので、Internet Explorerでダウンロード)
という環境にしてみました。
# RedHat系、C言語Gtkを使ってなかったっけ?という突っ込みは無しで。5年離れたら、世界は変わってます。


Pythonは後でコマンドプロンプトから実行するため、PATHを設定したほうが便利です。
# このため、一度UnInstallして、インストーラーの最初でPATHを設定しなおした。


とりあえず、コマンドプロンプトを起動し、Pythonが動くことを確認。


>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()


Pythonのモジュールのバージョン管理はpipを使うらしいので、インストールされているか確認。


>python -m pip -V
pip 9.0.3 from C:\Users\user_name\AppData\Local\Programs\Python\Python36\lib\site-packages (python 3.6)


pipのfreezeコマンドでバージョン確認???


>python -m pip freeze
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.


バージョンアップしてみる。
>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b
44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)

100% |████████████████████████████████| 1.3MB 660kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-10.0.1


pyqt5をインストールする。
>python -m pip install pyqt5
Collecting pyqt5
Downloading https://files.pythonhosted.org/packages/a7/22/67cc2bac6ae2cd3a7eab
b2a2e91638b94bdc6e0503747e49670ce44bb5b0/PyQt5-5.10.1-5.10.1-cp35.cp36.cp37.cp38

  • none-win_amd64.whl (81.0MB)

100% |████████████████████████████████| 81.0MB 60kB/s
Collecting sip<4.20,>=4.19.4 (from pyqt5)
Downloading https://files.pythonhosted.org/packages/30/fa/90ea79d7b6b21a50e16d
2e1214bd4d45390ee1b5393dc09c3785a3dc9c7e/sip-4.19.8-cp36-none-win_amd64.whl (51k
B)
100% |████████████████████████████████| 51kB 2.3MB/s
Installing collected packages: sip, pyqt5
The scripts pylupdate5.exe, pyrcc5.exe and pyuic5.exe are installed in 'C:\Use
rs\futoshi\AppData\Local\Programs\Python\Python36\Scripts' which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warn
ing, use --no-warn-script-location.
Successfully installed pyqt5-5.10.1 sip-4.19.8


なんか、インストールできた。
Python3.6のIDLEってのを起動して、ウィンドウを開いてみる。
>>> from PyQt5.QtWidgets import QApplication, QWidget
>>> app = QApplication(sys.argv)
>>> w = QWidget()
>>> w.resize(250,150)
>>> w.move(300, 300)
>>> w.setWindowTitle('Simple')
>>> w.show()
>>> sys.exit(app.exec_())


無事にウィンドウが開けた。Windows+Python+Qtのプログラム環境完成。しばらく勉強してみる予定。