`

Python3.4 + Qt5.4.0 + PyQt5.4.0+sip4.18-1

 
阅读更多

python3.4 + numpy + scipy + matplotlib + PyQt5.4.0
Ubuntu14.04(32位)+ Python3.4 + Qt5.4.0 + PyQt5.4.0+sip4.18-1

为了连接MySQL数据库,需要安装连接MySQL的驱动程序:
sudo apt-get install libqt4-sql-mysql

有一些项目中,还需要画一些数据曲线和统计图表等,而第三方的QWT库提供了这些功能。
sudo apt-get install libqwt5-qt4 libqwt5-qt4-dev

最后,关于集成开发环境我觉得QDevelop很不错,它跟Qt Designer结合的很好,而且有提示类成员函数的功能。运行以下命令安装:sudo apt-get install qdevelop
这样,使用Qdevelop编写代码和编译、调试,使用Qt Designer设计界面,开发效率较高。

sudo easy_install pip
sudo: easy_install: command not found on Debian/Ubuntu: =>

sudo apt-get install python-setuptools
Also, for python3, use easy_install3 and python3-setuptools

sudo apt-get install python3-setuptools
sudo easy_install3 pip

Installing pip script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Installing pip3.4 script to /usr/local/bin

sudo pip3.4 install virtualenvwrapper
which virtualenvwrapper.sh
which virtualenvwrapper_lazy.sh

mkdir ~/.virtualenvs
add the configuration to your ~/.bashrc file.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.4

add a command to the ~/.zshrc to run the activation script when my shell starts.
source `which virtualenvwrapper_lazy.sh`

which python3.4
/usr/bin/python3.4

mkvirtualenv testpy3 -p /usr/bin/python3.4

安装SIP

SIP是python调用C/C++库的必备模块。因此SIP是PyQt的依赖工具,安装PyQt之前必须先安装对应版本的SIP。PyQt编译时使用的SIP版本必须与python默认调用的SIP保持一致!否则python中是无法调用PyQt的。这里我们使用最新的sip-4.18.1
Ubuntu14.04中貌似是自带4.15版的SIP(or自己安装python扩展是自动安装的)。终端输入:
sip -V 
查看已安装SIP版本,如果存在其他版本,请查看python3的dist-packages目录下是否存在sip相关文件。如果存在将其删除:
sudo rm /usr/lib/python3/dist-packages/sip*

查看二者显示的版本是否一致。如不一致,需要重新执行上述删除过程和安装过程。版本不一致将意味着后面编译PyQt所使用的SIP和Python3调用的SIP的不一致,导致在Python3中调用PyQt的相关模块(from PyQt5 import QtCore)出现类似如下错误:
the sip module implements API v11.0 but the PyQt5.QtCore module requires API v11.1

reverting to sip 4.18-1 solved the issue for qt5, but py27-pyqt4 requires SIP v4.19.0 or later

(testpy3)$ cd sip-4.18-1
(testpy3)$ python configure.py

ERROR=>
siplib.c:20:20: fatal error: Python.h: No such file or directory

FIX=>
Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (ubuntu, debian...):
sudo apt-get install python-dev  # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs
For yum (centos, redhat, fedora...)
sudo yum install python-devel

(testpy3)$ sudo make
(testpy3)$ sudo make install

sip -V
4.18-1
python
>>>import sip 
>>>print(sip.SIP_VERSION_STR)
4.18-1

$ workon testpy3
(testpy3)$ deactivate


安装qt依赖的包
sudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libxcursor-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxrandr-dev libxrender-dev


ERROR=>Qt Designer plugin disabled because Python library couldn't be found

reinstall Qt by run=>

sudo ./qt-opensource-linux-x86-5.4.0.run
/opt/Qt5.4.0


export QTDIR=/opt/Qt5.4.0/5.4/gcc
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib


$ workon testpy3
$ cd /home/simon/Downloads/pypackages/PyQt-gpl-5.4
python configure.py

The PyQt5 Python package will be installed in
/home/simon/.virtualenvs/testpy3/lib/python3.4/site-packages.

sudo make
ERROR=>../qpy/QtCore/qpycore_chimera.cpp:503:22: error: ‘pyqt5ClassTypeDef’ was not declared in this scope

FIX=>reverting to sip 4.18-1 solved the issue for qt5, but py27-pyqt4 requires SIP v4.19.0 or later

sudo make install

ERROR=>
pyuic5: File format not recognized
make: [install_pyuic5] Error 1 (ignored)

Just ignore it. Your installation is fine. Open Terminal:
$python
>>> import PyQt5.Qt
if there is no error show up, you are done.


$ workon testpy3
$ cd /home/simon/Downloads/pypackages/PyQt-gpl-5.4
python configure.py -verbose --qmake /opt/Qt5.4.0/5.4/gcc/bin/qmake --sip-incdir=/usr/include/python3.4m

These PyQt5 modules will be built: QtCore, QtNetwork, QtXml, QtXmlPatterns,QtDBus.

bing search=>[PyQt5 QtGui]

Look at the output of configure.py, there should be a line:
These PyQt5 modules will be built: QtCore, QtGui, QtHelp, QtMultimedia, QtMultimediaWidgets, QtNetwork, QtOpenGL, QtPrintSupport, QtQml, QtQuick, QtSql, QtSvg, QtTest, QtWebKit, QtWebKitWidgets, QtWidgets, QtXml, QtXmlPatterns, QtDesigner, QtDBus, _QOpenGLFunctions_2_0, QtSensors, QtSerialPort, QtX11Extras, QtBluetooth, QtPositioning, QtQuickWidgets, QtWebSockets, Enginio, QtWebChannel, QtWebEngineWidgets

If this list is considerably shorter, missing QtGui etc, your installation may be missing OpenGL. In my case...
sudo apt-get install freeglut3-dev

python configure.py -verbose --qmake /opt/Qt5.4.0/5.4/gcc/bin/qmake --sip-incdir=/usr/include/python3.4m --verbose

sudo make
sudo make install

############################################################
cd /home/simon/.virtualenvs/testpy3/lib/python3.4/site-packages/PyQt5

Enginio.so                QtGui.so                QtPrintSupport.so  QtSql.so               QtWebSockets.so
__init__.py               QtHelp.so               QtQml.so           QtSvg.so               QtWidgets.so
_QOpenGLFunctions_2_0.so  QtMultimedia.so         QtQuick.so         QtTest.so              QtX11Extras.so
QtBluetooth.so            QtMultimediaWidgets.so  QtQuickWidgets.so  QtWebChannel.so        QtXmlPatterns.so
QtCore.so                 QtNetwork.so            QtSensors.so       QtWebEngineWidgets.so  QtXml.so
QtDBus.so                 QtOpenGL.so             QtSerialPort.so    QtWebKit.so       uic
QtDesigner.so             QtPositioning.so        Qt.so              QtWebKitWidgets.so
############################################################
from PyQt5.QtCore import *
from PyQt5.QtGui import *

 

git clone git://github.com/scipy/scipy.git scipy
git clone git://github.com/numpy/numpy.git numpy
最好不用开发版本


sudo apt-get install gfortran
#############普通安装#######################################
cd进setuptools-36.2.0的目录
$python3 setup.py build
$sudo python3 setup.py install
import setuptools


cd进numpy-1.13.1的目录
$python3 setup.py build --fcompiler=gnu95
$sudo python3 setup.py install --prefix=/usr/local

cd进scipy-0.19.1的目录
$python3 setup.py build --fcompiler=gnu95
$sudo python3 setup.py install --prefix=/usr/local

#############virtualenv安装#######################################
(testpy3)$sudo pip3.4 install numpy
=>/usr/local/lib/python3.4/dist-packages

(testpy3)$pip3.4 install numpy
=>/home/simon/.virtualenvs/testpy3/lib/python3.4/site-packages

[with or without sudo,install location differs]

(testpy3)$ python
import numpy
print(numpy.__version__)
print(numpy.__file__)
quit()

(testpy3)$pip3.4 install scipy
import scipy
print(scipy.__version__)
print(scipy.__file__)
quit()


安装matplotlib相对复杂一些
需要先安装其依赖的包libpng和freetype

sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev

(testpy3)$pip3.4 search matplotlib
(testpy3)$pip3.4 install matplotlib


import matplotlib
print(matplotlib.__version__)
print(matplotlib.__file__)
quit()


(testpy3)$pip3.4 install PyOpenGL

(testpy3)$pip3.4 install pyqtgraph

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics