1

I have the problem that when I run my code on a linux server I get:

ModuleNotFoundError: No module named '_sqlite3'

So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't. I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide. All solutions to this sqlite3 problem that I can find requires sudo commands.

Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?

I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!

Jeroen
  • 119
  • 2
  • 2
  • 8
  • what is this `my code` you are running? can you share? have you tried: `sudo apt install libsqlite3-dev` – MEdwin Jun 24 '19 at 13:23
  • I don't think the code is really important. The problem is that I don't have sqlite3 module. My code uses the openmdao module which happens to use the sqlite3 module. – Jeroen Jun 24 '19 at 13:25
  • try: `pip install pysqlite` – MEdwin Jun 24 '19 at 13:31
  • I did try that, installing pysqlite works, but I still get the same error message: No module named '_sqlite3' – Jeroen Jun 24 '19 at 13:34
  • can you download using `wget` and then `make install`? – MEdwin Jun 24 '19 at 14:40
  • I tried that, following this [link](https://www.thegeekstuff.com/2011/07/install-sqlite3). However the final command `make install` doesn't work: **/usr/bin/install: cannot create regular file '/usr/local/lib/libsqlite3.so.0.8.6': Permission denied** So is there a way how to do this is a more local directory which I have access to? – Jeroen Jun 24 '19 at 15:11
  • try this one. people says it works: `apt-get install libsqlite3-dev` or `apt-get install sqlite-devel`. Let me know if it works. – MEdwin Jun 24 '19 at 15:25
  • Actually I figured out how to get the `make install` to work. So I have sqlite3 now and it works. However, how do I get it to work with python? Should I re-install python now? And must the files of sqlite be in a specific location? – Jeroen Jun 24 '19 at 15:34
  • if you do `import sqlite3` in python what does it say? – MEdwin Jun 24 '19 at 15:47
  • `from sqlite3.dbapi2 import * File "/home/jriessbacher/python32/lib/python3.7/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3'` Those are the last lines – Jeroen Jun 24 '19 at 16:11

2 Answers2

1

While installing a python package in a Linux system without "sudo" privileges you can use

For Python 3

pip3 install --user pysqlite3

You can install any third party packages with the same method

pip3 install --user PACKAGE_NAME

The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !

Jithin
  • 173
  • 12
0

The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, @Ski has answered a similar question regarding python 2, which can be adopted to python 3:

$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install

$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install

$ ~/applications/bin/python

Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:

$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/
Artem Sobolev
  • 5,891
  • 1
  • 22
  • 40