Python/문제 해결
[PyQt5] This application failed to start because it could not find or load the Qt platform plugin ...
DWGoon
2015. 11. 23. 19:59
PyQt5 프로그램을 실행할 때, 아래와 같은 에러가 발생할 수 있다.
OS X의 경우:
This application failed to start because it could not find or load the Qt platform plugin "cocoa".
Windows의 경우:
This application failed to start because it could not find or load the Qt platform plugin "windows".
이러한 문제를 해결하는 임시방편 중 하나는, 자신의 시스템에 따라 적절한 plugin 디렉토리를 직접 명시적으로 지정해 주는 것이다.
나의 경우 OS X에서 "brew install"로 Qt5를 설치했기 때문에 아래와 같이 디렉토리를 지정하였다.
libpaths = QtWidgets.QApplication.libraryPaths()
libpaths.append("/usr/local/Cellar/qt5/5.5.1_2/plugins")
QtWidgets.QApplication.setLibraryPaths(libpaths)
Windows에서는 anaconda Python 3.4버전의 가상환경 하에 설치한 PyQt의 plugin 디렉토리를 지정해주었다
(py34는 내가 지정한 가상환경 이름이다).
libpaths = QtWidgets.QApplication.libraryPaths()
libpaths.append("C:/Users/dwlee/Anaconda/envs/py34/Lib/site-packages/PyQt5/plugins")
QtWidgets.QApplication.setLibraryPaths(libpaths)
운영체제에 따라 적절하게 실행되길 원한다면 아래와 같이 지정해 줄 수 있다.
if __name__ == '__main__':
libpaths = QtWidgets.QApplication.libraryPaths()
if sys.platform == 'darwin':
libpaths.append("/usr/local/Cellar/qt5/5.5.1_2/plugins")
QtWidgets.QApplication.setLibraryPaths(libpaths)
elif sys.platform == 'win32':
libpaths.append("C:/Users/dwlee/Anaconda/envs/py34/Lib/site-packages/PyQt5/plugins")
QtWidgets.QApplication.setLibraryPaths(libpaths)
app = QtWidgets.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec())
참고: