상세 컨텐츠

본문 제목

윈도우에서 KoNLPy 파이썬 환경 구축하기

AI/KoNLPy

by cepiloth 2021. 7. 10. 15:57

본문

728x90
반응형

최종 설치 버전

Python 3.8.8 rc1
OpenJDK 18-ea
JPype1.2

초기에 Python 버전 3.9 KoNLPy 1.3_x64 버전으로 설치를 하였는데 버전이 안 맞는지 계속 에러가 발생하였습니다.

 

 윈도우 환경에서 KoNLPy를 사용하기 위해서 먼저 파이썬과 Visual Studio Code를 설치합니다. 터미널을 실행하고 konlpy 명령으로 패키지를 설치합니다. KoNLPy 공식 웹사이트에 각 플랫폼별 설치 매뉴얼이 작성되어 있습니다.

https://konlpy.org/ko/latest/install/#id2

 

설치하기 — KoNLPy 0.5.2 documentation

우분투 Supported: Xenial(16.04.3 LTS), Bionic(18.04.3 LTS), Disco(19.04), Eoan(19.10) Install dependencies # Install Java 1.8 or up $ sudo apt-get install g++ openjdk-8-jdk python3-dev python3-pip curl Install KoNLPy $ python3 -m pip install --upgrade p

konlpy.org

 

파이썬 설치

아래 웹사이트에서 다운로드할 수 있습니다.

https://www.python.org/downloads/

 

Download Python

The official home of the Python Programming Language

www.python.org

 

Visual Studio Code 설치

IDE는 서브라임 텍스트 혹은 Vim 등을 사용해도 됩니다.

https://code.visualstudio.com/

 

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

 

JDK 환경 설정

JDK 환경변수를 추가해야 합니다. Oracle JAVA의 경우 라이선스 문제가 있어 무료 라이선스인 AdotOpenJDK로 설치하였습니다.

https://adoptopenjdk.net/

 

AdoptOpenJDK

AdoptOpenJDK provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure. Supported platforms include Linux, macOS, Windows, ARM, Solaris, and AIX.

adoptopenjdk.net

 

또는 OpenJDK를 다운로드하여 설치해도 무방합니다.

https://openjdk.java.net/

 

OpenJDK

Download and install the open-source JDK for most popular Linux distributions. Oracle's free, GPL-licensed, production-ready OpenJDK JDK 16 binaries are at jdk.java.net/16; Oracle's commercially-licensed JDK 16 binaries for Linux, macOS, and Windows, bas

openjdk.java.net

 

KoNLPy 패키지 설치

파이썬이 설치가 완료되면은 터미널 창에서 pip 명령으로 KoNLPy 패키지를 설치할 수 있습니다.

pip install konlpy

 

정상적으로 설치가 되었는 아래 명령으로 확인합니다.

pip show konlpy

 

Requires를 보게 되면 numpy, beatifulsoup4, colorama, lxml, tweepy, JPype1 등 추가 설치되어 있는 것을 알 수 있습니다.

 

 JPype1 이 잘못 설치가 되어 실행되지 않을 경우가 있을지 모르니 현재 컴퓨터의 환경에 맞게 JPype1을 재 설치 필요할 수도 있습니다. 컴퓨터의 환경에 따른 패키지는 아래 웹 사이트에서 확인할 수 있습니다.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype

 

Python Extension Packages for Windows - Christoph Gohlke

by Christoph Gohlke, Laboratory for Fluorescence Dynamics, University of California, Irvine. Updated on 7 July 2021 at 21:21 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

 

JPype1 이 정상적으로 설치되었지만 아래와 같은 에러가 발생할 수 도 있다. https://visualstudio.microsoft.com/ko/visual-cpp-build-tools/ 웹사이트로 이동하여 Visual C++ 용 Build Tools를 다운로드합니다.

 

Visual Studio Build Tools 2019 설치

컴퓨터에 Visual Studio 가 설치되어있는 환경이라면 위에 에러는 발생하지 않습니다. 아무것도 없는 상황에서 발생함으로 이미 설치되어있는 환경에서는 다음 단계로 가도 무방합니다.

 

테스트 코드

 Python 버전이랑 JPype 버전이랑 무슨 차이가 있는지 3.9에서 동작하지 않아 우여곡절 끝에 코드를 실행합니다. morphs라는 메서드는 문장에서 형태소를 추출하는 기능을 합니다. 이외에 nouns는 명사 추출 품사 부착의 기능을 한다고 합니다.

 테스트 코드에서 import 한 Okt 는 Open Korean Text의 줄임말로 https://github.com/open-korean-text/open-korean-text 오픈 소스 한국어 분석기이며 과거 트위터 형태소 분석기이며 이외에도 Hannanum, Kkma, Komoran, Mecab 등이 있습니다.

from konlpy.tag import Okt
okt = Okt()  
token = okt.morphs("엄마가 방에 들어가신다.")
print(token)
token = okt.morphs("엄마 가방에 들어 가신다.")  
print(token)

 

출력 결과

Okt 만 import 하여서 출력했을 때의 결과입니다.

 

환경설정 한참 하다가 문득 이런 제 모습이 생각나네요. 차라리 COLAB에서 할걸.. 

728x90
반응형

'AI > KoNLPy' 카테고리의 다른 글

COLAB 에서 KoNLPy WordCloud 설치하기  (0) 2021.07.10
KoNLPy 로 워드 클라우드 만들어 보기 IDEA  (0) 2021.07.10

관련글 더보기

댓글 영역