-1

i am a beginner i need to create a python virtual_environment for installing Django. I am using the following steps for installing python and virtualenv

cd /usr/src/
wget http://www.python.org/ftp/python/3.5.1./Python-3.5.1.tgz
tar zxf Python-3.5.1.tgz
cd python-3.5.1
mkdir /usr/local/python-3.5
./configure --prefix=/usr/local/python'.$python.' --with-threads --enable-shared --with-zlib=/usr/include && make && make altinstall
echo "/usr/local/python3.5/lib" > python3.5.conf
mv python3.5.conf /etc/ld.so.conf.d/python3.5.conf
/sbin/ldconfig
ln -sfn /usr/local/python3.5/bin/python3.5 /usr/bin/python3.5
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-11.3.1.tar.gz
tar xzf setuptools-11.3.1.tar.gz
cd setuptools-11.3.1
/usr/local/python3.5/bin/python3.5 setup.py install
/usr/local/python3.5/bin/easy_install-3.5 pip
ln -sfn /usr/local/python3.5/bin/pip3.5 /usr/bin/pip3.5
/usr/local/python3.5/bin/pip3.5 install virtualenv

then i am created a virtualenv based on this, and enter into python shell and use

import sqlite

i got following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'sqlite'

And i tried to run a django project installed in the virtalenv i got following errors.

raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'

I am using CentOS release 6.8 (Final).

nidhin
  • 359
  • 1
  • 3
  • 13
  • [Check other solutions](http://stackoverflow.com/questions/11394013/problems-with-python-2-7-3-on-centos-with-sqlite3-module) it may be help you!! – mahendra kamble Oct 05 '16 at 11:20

2 Answers2

3

The python-bundled sqlite package is called sqlite3: https://docs.python.org/3.6/library/sqlite3.html

So, just do

import sqlite3

and you should be good.

EDIT

I only now realized that you're building python yourself. So that's probably why the sqlite3 module is missing. Check the output of the configure call whether sqlite3 is mentioned. I assume you'd have to get the development packages.

sebastian
  • 9,526
  • 26
  • 54
  • Python 3.5.1 (default, Oct 5 2016, 06:38:10) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 Traceback (most recent call last): File "", line 1, in File "/usr/local/python3.5/lib/python3.5/sqlite3/__init__.py", line 23, in from sqlite3.dbapi2 import * File "/usr/local/python3.5/lib/python3.5/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named '_sqlite3' – nidhin Oct 05 '16 at 11:23
0

Any reason you are not using the EPEL Repository to install python?