1. python 설치
$ sudo apt install python3.8
2. python3 확인
$ python3
Python 3.6.9 (default, Mar 10 2023, 16:46:00)
$ python3.8
Python 3.8.0 (default, Mar 10 2023, 16:46:00)
3. python 명령어 실행 시 python 3.8로 연결
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
4. python 확인
$ python -V
Python 3.8.0
5. Python 가상 환경 설정
$ sudo apt-get install python3.8-venv
$ python -m venv venv
$ source venv/bin/activate
(venv) bctone@localhost:~/abc$ python
Python 3.8.0 (default, Dec 9 2021, 17:53:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
6. app.py 실행
$ source venv/bin/activate
(venv) $ sudo apt install python-pip
(venv) $ pip install --upgrade pip
(venv) $ pip install flask
(venv) $ pip install flask_cors
(venv) $ pip install pymongo
(venv) $ pip install konlpy
7. Mecab 설치
(1) 공식문서 명령어
$ sudo apt install build-essential autoconf
$ bash <(curl -s https://raw.githubusercontent.com/konlpy/konlpy/master/scripts/mecab.sh)
하지만 여전히 NameError: name ‘Tagger’ is not defined 에러가 뜹니다. 해결하는 방법은 mecab을 직접 설치하는 것입니다.
(2) libmecab.so.2 링크 생성
$ cd /tmp/
$ sudo apt install build-essential autoconf
$ curl -LO https://bitbucket.org/eunjeon/mecab-ko/downloads/mecab-0.996-ko-0.9.2.tar.gz
$ tar zxfv mecab-0.996-ko-0.9.2.tar.gz
$ curl -LO https://bitbucket.org/eunjeon/mecab-ko-dic/downloads/mecab-ko-dic-2.1.1-20180720.tar.gz
$ tar -zxvf mecab-ko-dic-2.1.1-20180720.tar.gz
$ cd /tmp/mecab-ko-dic-2.1.1-20180720
$ sudo ldconfig
$ sudo ldconfig -p | grep /usr/local/lib
libmecab.so.2 (libc6,x86-64) => /usr/local/lib/libmecab.so.2
libmecab.so (libc6,x86-64) => /usr/local/lib/libmecab.so
(3) mecab-ko 설치
$ cd /tmp/mecab-0.996-ko-0.9.2
$ ./configure
$ make
$ make check
$ sudo make install
(4) mecab-ko-dic 설치
$ cd /tmp/mecab-ko-dic-2.1.1-20180720
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
libmecab.so.2가 있는지 확인
$ ls /usr/local/lib/libmecab.so.2
/usr/local/lib/libmecab.so.2
ld.so.conf에 /usr/local/lib 추가
$ sudo vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib <-- 추가
ld.so.conf 설정을 반영
$ ldconfig
(5) mecab-python 설치
$ pip install mecab-python3
참고: Ubuntu 18.04 konlpy & mecab install – 딥린이의 작업노트 (raki-1203.github.io)