ImportError:没有名为PytQt5的模块

时间:2013-12-19 03:21:42

标签: python pyqt5

以下是我的python,qt和sip版本

root@thura:~# python -V
Python 2.7.3
root@thura:~# qmake --version
QMake version 3.0
Using Qt version 5.0.2 in /usr/lib/i386-linux-gnu
root@thura:~# sip -V
4.15.3

我尝试通过this

跟随导入PyQt5
from PyQt5.QtWidgets import QtGui, QtCore

我收到以下错误

  

ImportError:没有名为PyQt5.QtWidgets的模块

如何解决此错误。

更新=====================

当我尝试使用PyQt4时,我遇到了以下错误。

  

从PyQt4.QtCore导入pyqtSlot作为Slot RuntimeError:sip   模块实现了API v10.0到v10.1,但是PyQt4.QtCore模块   需要API v8.1

更新2013-12-20 ======================================

  

1)从here

下载sip-4.15.3.tar.gz      

2)提取sip-4.15.3.tar.gz

     

3)将sip-4.15.3复制到/ home / thura

     

4)输入“cd /home/thura/sip-4.15.3”

     

5)键入“python configure.py”,按回车键,按照说明操作   (输入yes并按回车键)

     

6)输入“make”,按回车键入“make install”,按回车键

     

7)从here

下载PyQt-gpl-5.1.1.tar.gz      

8)提取PyQt-gpl-5.1.1.tar.gz

     

9)将PyQt-gpl-5.1.1文件夹复制到/ home / thura文件夹。

     

10)输入“cd /home/thura/PyQt-gpl-5.1.1”

     

11)键入“python configure.py”,按回车键,然后按   说明(输入yes并按回车键)

     

12)输入“make”,按回车键入“make install”,按回车键

更新2013-12-20 =====================

再次重做之后。我收到以下错误

make[2]: Entering directory `/home/thura/PyQt/qpy/QtDBus'
make[2]: Nothing to be done for `install'.
make[2]: Leaving directory `/home/thura/PyQt/qpy/QtDBus'
make[1]: Leaving directory `/home/thura/PyQt/qpy'
cd QtCore/ && ( test -e Makefile || /usr/lib/i386-linux-gnu/qt5/bin/qmake /home/thura/PyQt/QtCore/QtCore.pro -o Makefile ) && make -f Makefile install
make[1]: Entering directory `/home/thura/PyQt/QtCore'
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DSIP_PROTECTED_IS_PUBLIC -Dprotected=public -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++ -I. -I/usr/local/include/python2.7 -I../qpy/QtCore -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -o sipQtCoreQtWindowStates.o sipQtCoreQtWindowStates.cpp
In file included from sipQtCoreQtWindowStates.cpp:24:0:
sipAPIQtCore.h:28:17: fatal error: sip.h: No such file or directory
compilation terminated.
make[1]: *** [sipQtCoreQtWindowStates.o] Error 1
make[1]: Leaving directory `/home/thura/PyQt/QtCore'
make: *** [sub-QtCore-install_subtargets-ordered] Error 2

7 个答案:

答案 0 :(得分:25)

如果您使用的是ubuntu,只需使用Bridging Header.命令安装pyqt5:

Ld /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/IntermediateBuildFilesPath/[PROJECT NAME].build/Release-iphoneos/[PROJECT NAME].build/Objects-normal/armv7/[PROJECT NAME] normal armv7
    cd "/Users/user1/Desktop/[PROJECT NAME]"
    export IPHONEOS_DEPLOYMENT_TARGET=9.2
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk -L/Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/BuildProductsPath/Release-iphoneos -F/Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/BuildProductsPath/Release-iphoneos -F/Users/user1/path/to/facebook-sdks/FacebookSDKs-iOS-20160412 -filelist /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/IntermediateBuildFilesPath/[PROJECT NAME].build/Release-iphoneos/[PROJECT NAME].build/Objects-normal/armv7/[PROJECT NAME].LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -miphoneos-version-min=9.2 -dead_strip -fembed-bitcode -Xlinker -bitcode_verify -Xlinker -bitcode_hide_symbols -Xlinker -bitcode_symbol_map -Xlinker /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/BuildProductsPath/Release-iphoneos -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -add_ast_path -Xlinker /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/IntermediateBuildFilesPath/[PROJECT NAME].build/Release-iphoneos/[PROJECT NAME].build/Objects-normal/armv7/[PROJECT_NAME].swiftmodule -framework Bolts -framework FBSDKCoreKit -framework FBSDKShareKit -Xlinker -dependency_info -Xlinker /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/IntermediateBuildFilesPath/[PROJECT NAME].build/Release-iphoneos/[PROJECT NAME].build/Objects-normal/armv7/[PROJECT NAME]_dependency_info.dat -o /Users/user1/Library/Developer/Xcode/DerivedData/[PROJECT_NAME]-aghpdhmffnurkjfosupvbolgwxmn/Build/Intermediates/ArchiveIntermediates/[PROJECT NAME]/IntermediateBuildFilesPath/[PROJECT NAME].build/Release-iphoneos/[PROJECT NAME].build/Objects-normal/armv7/[PROJECT NAME]

clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)

apt-get

但是,在Ubuntu 14.04上,python-pyqt5包被省略[source],需要手动安装[source]

答案 1 :(得分:8)

这可以通过安装pyqt with brew

在MacOS X下解决
brew install pyqt

答案 2 :(得分:7)

在得到@Blender,@ ekhumoro和@Dan的帮助之后,我比以前更了解Linux和Python。谢谢。我得到了@ekhumoro的想法,我没有正确安装PyQt5。所以我删除了PyQt5文件夹并再次下载。从一开始就重做一切。

重做之后,我在上一次更新时得到了错误。所以,当我在堆栈搜索时,我从here

获得了以下解决方案
sudo ln -s /usr/include/python2.7 /usr/local/include/python2.7

然后,我一步一步地做了“sudo make”和“sudo make install”。在“sudo make install”之后,我收到以下错误。但我忽略了它,我用qt设计师创建了一个简单的设计。我把它转换成了pyuic5的python文件。一切进展顺利。

install -m 755 -p /home/thura/PyQt/pyuic5 /usr/bin/
strip /usr/bin/pyuic5
strip:/usr/bin/pyuic5: File format not recognized
make: [install_pyuic5] Error 1 (ignored)

答案 3 :(得分:5)

pip install pyqt5用于ubuntu的python3

答案 4 :(得分:2)

这可能意味着python不知道PyQt5的位置。要进行检查,请进入交互式终端并输入:

import sys
print sys.path

您可能需要做的是将包含PyQt5模块的目录添加到PYTHONPATH环境变量中。如果您使用bash,请按以下方式进行操作:

在shell中键入以下内容,并将其添加到文件末尾~/.bashrc

export PYTHONPATH=/path/to/PyQt5/directory:$PYTHONPATH

其中/path/to/PyQt5/directory是PyQt5库所在文件夹的路径。

答案 5 :(得分:0)

在windows上,“pip install pyqt5”,帮我解决了。

答案 6 :(得分:0)

可能是python版本不同造成的,看你用的是哪个版本的python,对我来说全局版本是2.7,虚拟环境安装的python版本是3.8,所以有区别,所以我运行main.js。 py 在环境中,它可以工作。

enter image description here