[Python][OpenGL] OpenGL.error.NullFunctionError 에러 해결 | Unofficial Windows Binaries for Python Extension Packages 설치 방법
들어가기
Windows, Python에서 OpenGL을 사용하는 것은 힘들다.
코드 한 줄마다 이상한 오류가 발생한다. 분명 import를 했는데, 또 import를 하라던가.
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
와 같은 에러는 너무나도 많다.
이 문제를 해결하기 위해 OpenGL을 여러번 지웠다 깔았다 했지만, 가장 궁극적인 해결법은 리눅스에서 개발하던가, 윈도우에 맞게 수정한 라이브러리로 바꾸는 것이다.
절차
1. Download the package wheel
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
Archived: Python Extension Packages for Windows - Christoph Gohlke
Archived: Python Extension Packages for Windows - Christoph Gohlke by Christoph Gohlke. Updated on 26 June 2022 at 07:27 UTC. This page provides 32 and 64-bit Windows binaries of many scientific open-source extension packages for the official CPython
www.lfd.uci.edu
위 사이트에서 적절한 wheel을 다운받는다.
PyOpenGL: 패키지 이름
3.1.6: 패키지 버전
cp39: Python 버전
amd64: 64비트
사용하는 파이썬 버전 등 각자의 개발환경에 따라, 적절하게 다운받자.
필자가 다운받은 wheel은
PyOpenGL-3.1.6-cp39-cp39-win_amd64.whl
PyOpenGL_accelerate-3.1.6-cp39-cp39-win_amd64.whl
총 2가지이다.
2. 설치
.whl이 있는 디렉토리로 이동하여 터미널을 연다.
필자는 PyCharm에 있는 터미널로 열었다.
그리고 다음과 같이 실행한다.
# 기존에 설치한 패키지가 없을 경우
pip install PyOpenGL-3.1.6-cp39-cp39-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.6-cp39-cp39-win_amd64.whl
# 기존에 설치한 패키지가 있을 경우
pip install PyOpenGL-3.1.6-cp39-cp39-win_amd64.whl --ignore-installed
pip install PyOpenGL_accelerate-3.1.6-cp39-cp39-win_amd64.whl --ignore-installed
필자는 안전하게 PyOpenGL과 PyOpenGL-accelerate를 지우고 설치했지만, 귀찮은 사람은 --ignore-installed를 붙이고 실행해보자.
3. 완료 ?
일단 오류는 해결되었다! 이제 OpenGL을 써보도록 하자.