安装pyQt4时找不到sip.h

3 投票
1 回答
6478 浏览
提问于 2025-04-18 12:04

我在我的Ubuntu 13.04 Linux虚拟机上尝试安装PyQt-x11-gpl-4.11,运行configure-ng.py的时候没有问题,但在使用make时却出现了下面的错误信息,**

root@ubuntu:/home/yanwang/Downloads/PyQt-x11-gpl-4.11# make
cd QtCore/ && make -f Makefile 
make[1]: Entering directory `/home/yanwang/Downloads/PyQt-x11-gpl-4.11/QtCore'
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DSIP_PROTECTED_IS_PUBLIC -Dprotected=public -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I/usr/local/include/python2.7 -I../qpy/QtCore -I. -o sipQtCoreQTimer.o sipQtCoreQTimer.cpp
In file included from sipQtCoreQTimer.cpp:29:0:
sipAPIQtCore.h:33:17: fatal error: sip.h: No such file or directory
compilation terminated.
make[1]: *** [sipQtCoreQTimer.o] Error 1
make[1]: Leaving directory `/home/yanwang/Downloads/PyQt-x11-gpl-4.11/QtCore'
make: *** [sub-QtCore-make_default-ordered] Error 2
root@ubuntu:/home/yanwang/Downloads/PyQt-x11-gpl-4.11# 

SIP文件安装在下面的目录:

/home/iriswang/Downloads/sip-4.16.1

而PyQt文件则在这个目录下:

/home/iriswang/Downloads/PyQt-x11-gpl-4.11

我已经设置了环境变量,让它包含了sip的目录:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/iriswang/Downloads/sip-4.16.1:/home/iriswang/Qt5.3.1/5.3/gcc_64/bin

但是,看起来它还是找不到sip.h这个文件。请问我该怎么办?顺便说一下,我已经安装了python-dev这个包,所以应该不是这个问题。而且我检查了sip是否成功安装,似乎也没问题:**

root@ubuntu:/home/iriswang/Downloads# sip -h
Usage:

    sip [-h] [-V] [-a file] [-b file] [-B tag] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-P] [-r] [-s suffix] [-t tag] [-T] [-w] [-x feature] [-X id:file] [-z file] [file]
where:
    -h          display this help message
    -V          display the sip version number
    -a file     the name of the QScintilla API file [default not generated]
    -b file     the name of the build file [default none generated]
    -B tag      add tag to the list of timeline backstops
    -c dir      the name of the code directory [default not generated]
    -d file     the name of the documentation file (deprecated) [default not generated]
    -e          enable support for exceptions [default disabled]
    -g          always release and reacquire the GIL [default only when specified]
    -I dir      look in this directory when including files
    -j #        split the generated code into # files [defaul
...

非常感谢!**

1 个回答

2

在Ubuntu上安装PyQt时,这似乎是一个常见的问题。我查了一下,发现有两种可能的解决办法。

(1) 你需要在Makefiles中更新你的Python头文件,确保链接的是 /usr/include/python2.7 而不是 /usr/local/include/python2.7. 你可以参考这个链接来找到简单的解决方法:

编译PyQt5时出现致命错误:Python.h不存在

(2) 你可以安装PyQt4.10,而不是PyQt4.11。其他用户反映说PyQt4.11安装不太成功。这里有个链接可以获取更多信息:

http://iqbalnaved.wordpress.com/2014/05/31/installing-pyqt4-for-python-2-7-6-in-virtual-environement-in-ubuntu-14-04/

我建议你选择第一种方法,因为你应该使用最新版本的PyQt。记得多做一些研究,因为我觉得你的问题并不是个例。

撰写回答