玩转树莓派-RaspBerry,使用Python开发定制界面

摘要: 使用Python开发界面,可以用PyQt、WxPython或PyGTK,这里主要介绍PyQt的安装,下载源码进行编译和部署到系统目录。

1 准备SD卡8G以上,16G更佳。

    编译过程中,会耗用大量存储空间。一定在编译之前运行sudo raspi-config,选择expand file system扩展SD卡的分区。

    如果空间不够,会导致运行挂起。使用df -h可查看存储卡的可用容量。

2 更新资源的索引清单

sudo apt-get update (从服务上下载索引清单)
sudo apt-get upgrade (比较索引清单,更新依赖关系)

3 安装 python-dev

sudo apt-get install python-dev

    否则在编译SIP时,会提示 fatal error: Python.h: No such file or directory

4 安装libqt4-dev

sudo apt-get install libqt4-dev
#或者
sudo apt-get install qt4-dev-tools

    否则在编译PyQt时会提示 Error:Make sure you have a working Qt qmake on your PATH or use the -q argument to explicitly specify a working Qt qmake 5。

    依次安装SIP和PyQt。

    安装SIP:

wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.6/sip-4.16.6.tar.gz
tar vxf sip-4.16.6.tar.gz
cd sip-4.16.6
python configure.py
make
make install

    安装PyQt4:

#wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10/PyQt-x11-gpl-4.10.tar.gz
wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.4/PyQt-x11-gpl-4.10.4.tar.gz/download
cp download PyQt-x11-gpl-4.10.4.tar.gz  
tar vxf PyQt-x11-gpl-4.10.4tar.gz
cd PyQt-xll-gpl-4.10.4
python configure.py
make
make install


5 运行Python&GUI的源代码

    进入PyQT下面的Examples目录,使用python *.py方式运行。

    下面这张图是周末两天的成果,虽说很是简陋,但运行成功的一刻,一切都值得了:)。

玩转树莓派-RaspBerry,使用Python开发定制界面_第1张图片


This is a slightly modified answer of @Flyte which worked for me on CentOS 6.5

  • activate your virtualenv(optional in case you want to install in virtualenv)
  • wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.15.4/sip-4.15.4.zip(your corresponding version)
  • unzip sip-4.15.4.zip
  • cd sip-4.15.4
  • python configure.py --incdir=/opt/include/python2.7(path where python is located)
  • make and make install this completes the installation of SIP one of the prerequsite -Then to install PyQt4
  • wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.3/PyQt-x11-gpl-4.10.3.tar.gz
  • tar zxvf PyQt-x11-gpl-4.10.3.tar.gz
  • cd PyQt-x11-gpl-4.10.3
  • python2.7 configure.py -k --qmake /usr/bin/qmake-qt4
  • make and finally make install

this worked for me hope it helps you also. also make sure you have proper version of qt installed usually need to use qt version>4.7



你可能感兴趣的:(玩转树莓派-RaspBerry,使用Python开发定制界面)