YUMSERV
반응형

1. ModuleNotFoundError: No module named '_sqlite3'

* pyenv 환경에서 진행

# python manage.py createuperuser
...
  packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "/root/.pyenv/versions/venv_3.9.4/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/root/.pyenv/versions/venv_3.9.4/lib/python3.9/site-packages/django/db/utils.py", line 208, in create_connection
    backend = load_backend(db["ENGINE"])
  File "/root/.pyenv/versions/venv_3.9.4/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
    return import_module("%s.base" % backend_name)
  File "/root/.pyenv/versions/3.9.4/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/root/.pyenv/versions/venv_3.9.4/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 15, in <module>
    from sqlite3 import dbapi2 as Database
  File "/root/.pyenv/versions/3.9.4/lib/python3.9/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/root/.pyenv/versions/3.9.4/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

 

# python
Python 3.9.4 (default, Jul  7 2022, 23:21:40) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.pyenv/versions/3.9.4/lib/python3.9/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/root/.pyenv/versions/3.9.4/lib/python3.9/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

-> yum install sqlite sqlite-devel

pyenv 환경 다시 재설치
# CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.9.4

 

 

sqlite3 버전확인.

# python3
Python 3.9.4 (default, Jul 10 2022, 14:34:24) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'

 

 

2. django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).

-> 최신버전 sqlite 설치

 

wget https://sqlite.org/2022/sqlite-autoconf-3390000.tar.gz
tar xvfz sqlite-autoconf-3390000.tar.gz
cd sqlite-autoconf-3390000
./configure --prefix=/usr/local/
make && make install
cp -arp /usr/local/bin/sqlite3 /usr/bin/sqlite3

sqlite3 --version
3.39.0 2022-06-25 14:57:57 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918


그러나 PYTHON 버전에서 sqlite로 했을 때에는 기존 버전을 바라보고 있다.

 

# python3
Python 3.9.4 (default, Jul 10 2022, 14:34:24) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'

 

라이브러리 위치를 최신버전을 설치한 sqlite3쪽으로 향하게 해준다.
# echo $LD_LIBRARY_PATH

# export LD_LIBRARY_PATH="/usr/local/lib"
# echo $LD_LIBRARY_PATH
/usr/local/lib


영구적으로 라이브러리 위치를 지정하고 싶다면
# vi /etc/ld.so.conf.d/sqlite.conf
/usr/local/lib

# python3
Python 3.9.4 (default, Jul 10 2022, 14:34:24) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.39.0'

 

 

반응형
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!