2

We have different python version installed and specifically using python3.7 so I have edited my .bashrc file. We are using Centos7 with Linux server.

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
alias python=python3.7
alias pip=pip3.7


[xyz@innolx20122 ~]$ python
python             python2.7          python3.6          python3.7          python3.7m-config
python2            python3            python3.6m         python3.7m

[xyz@innolx20122 ~]$ which sqlite3
/usr/bin/sqlite3

Its working with python2.7 and python3.6 version

[xyz@innolx20122 ~]$ python2.7
Python 2.7.5 (default, Apr  2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

[xyz@innolx20122 ~]$ python3.6
Python 3.6.8 (default, Apr  2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3

It's not working with python3.7 version

[xyz@innolx20122 ~]$ python3.7
Python 3.7.0 (default, Sep  3 2020, 09:25:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] 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 "/usr/local/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

Update-

We installed python following instruction in the below link Python3.7 installation link

Hence my python3.7 version is installed at root level

[root@innolx20122 ~]# ls
anaconda-ks.cfg  Python-3.7.0  Python-3.7.0.tgz
[root@innolx20122 ~]# cd Python-3.7.0
[root@innolx20122 Python-3.7.0]# ls
aclocal.m4    config.status  Doc         Lib              Mac              Misc     PC              pyconfig.h     python-config     setup.py
build         config.sub     Grammar     libpython3.7m.a  Makefile         Modules  PCbuild         pyconfig.h.in  python-config.py  Tools
config.guess  configure      Include     LICENSE          Makefile.pre     Objects  Programs        python         python-gdb.py
config.log    configure.ac   install-sh  m4               Makefile.pre.in  Parser   pybuilddir.txt  Python         README.rst

I saw one link on stack overflow suggesting some workaround. fix Sqlite3 issue

Kindly suggest if it's ok to run below commands from same root directory itself

yum install sqlite-devel

./configure
make && make altinstall
8
  • 1
    How were the modules in /usr/local installed?
    – jsbillings
    Sep 23, 2020 at 11:39
  • @ jsbillings .. some one else installed python3.7 version. I will check but looks like he followed given link instructions osradar.com/install-python-3-7-on-centos-7-and-fedora-27-28 Sep 23, 2020 at 14:58
  • [xyz@innolx20122 ~]$ echo $PATH /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/eksinvi/.local/bin:/home/eksinvi/bin Sep 23, 2020 at 15:51
  • 3
    It is NOT safe to follow those instructions in the answer on that page. Replacing /usr/bin/python on CentOS 7 will break a bunch of core components, including yum. You need to either use a packaged python and stop using your broken python installation in /usr/local, or fix your broken python installation. It appears to have a bad sqlite module installation.
    – jsbillings
    Sep 23, 2020 at 21:32
  • 1
    Can you use the python 3 that is part of the OS? Otherwise get support from the person who installed your broken python in /usr/local/.
    – jsbillings
    Sep 25, 2020 at 19:36

1 Answer 1

3

I logged in as root user.

[root@innolx20122 ~]# ls
anaconda-ks.cfg  Python-3.7.0  Python-3.7.0.tgz

and then navigate to the Python-3.7.0 directory

[root@innolx20122 Python-3.7.0]# ls
aclocal.m4    config.status  Doc         Lib              Mac              Misc     PC              pyconfig.h     python-config     setup.py
build         config.sub     Grammar     libpython3.7m.a  Makefile         Modules  PCbuild         pyconfig.h.in  python-config.py  Tools
config.guess  configure      Include     LICENSE          Makefile.pre     Objects  Programs        python         python-gdb.py
config.log    configure.ac   install-sh  m4               Makefile.pre.in  Parser   pybuilddir.txt  Python         README.rst

thereafter ran below commands to resolve the issue.

yum install sqlite-devel

./configure
make && make altinstall


[xyz@innolx20122 ~]$ python3.7
Python 3.7.0 (default, Sep 26 2020, 23:18:27)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>>
1
  • omg it worked for me (python3.8.3) thank you
    – sooyeon
    Nov 14, 2022 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .