由于ubuntu存储库中的官方pyqt5安装似乎缺乏对QtQuick的支持,我试图从源代码安装pyqt5。安装本身似乎工作正常,但是当运行使用PyQt5的python脚本时,python抱怨说它找不到那个PyQt。Python没有找到自定义的PyQt5
建立sip 4.15.5后,我下载了PyQt5.2。这应该是我的版本的Qt(的qmake --version
输出)兼容:
QMake version 3.0
Using Qt version 5.2.0 in /opt/qt5.1.1/5.2.0/gcc_64/lib
我跑
的PyQt的configure.py的输出可以在这里找到:https://gist.github.com/Mitmischer/8677889。
pyqt的安装输出可以在这里找到:https://gist.github.com/Mitmischer/8677780。
经过sudo make install
后,我可以在/usr/lib/python3.3/site-packages
的文件夹中看到一个文件夹PyQt5
,这很不错。但是,如果我跑的猫PyQt5/__init__.py
,里面有没有实际代码:
# Copyright (c) 2014 Riverbank Computing Limited <[email protected]>
#
# This file is part of PyQt5.
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file. Please review the
# following information to ensure the GNU General Public License version 3.0
# requirements will be met: http://www.gnu.org/copyleft/gpl.html.
#
# If you do not wish to use this file under the terms of the GPL version 3.0
# then you may purchase a commercial license. For more information contact
# [email protected]
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
是的,这一切的是那个文件里面。我不知道这是否应该是这样,但对我来说这看起来很奇怪。此外(ls PyQt5
):
__init__.py QtCore.so QtGui.so QtMultimediaWidgets.so QtPositioning.so QtQuick.so Qt.so QtTest.so QtX11Extras.so
_QOpenGLFunctions_2_0.so QtDBus.so QtHelp.so QtNetwork.so QtPrintSupport.so QtSensors.so QtSql.so QtWebKit.so QtXmlPatterns.so
QtBluetooth.so QtDesigner.so QtMultimedia.so QtOpenGL.so QtQml.so QtSerialPort.so QtSvg.so QtWidgets.so uic/
看起来不像pythonic。
至于其他地方的建议,我(希望)适当设置我的PYTHONPATH:
> echo $PYTHONPATH
/usr/lib/python3.3/site-packages/
现在,如果我启动交互式python3.3
-session(或脚本),PyQt5无法找到:
Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'PyQt5'
>>>
有没有其他人试图从源代码安装PyQt5?我能做些什么来使PyQt工作?
似乎安装成功。 '__init __。py'应该是空的:'PyQt5'只是一个名字空间。 '* .so'文件都是编译后的扩展模块。我能想到的唯一的事情是,你以某种方式运行“错误的”python3.3 - 你有多个安装? – ekhumoro
@ekhumoro:我猜不是:'which -a python3.3'只显示'/ usr/bin/python3.3' –
好奇。作为一个实验,打开一个新的交互式会话,然后执行'os.chdir('/ usr/lib/python3.3/site-packages')'并尝试导入PyQt5。 – ekhumoro