简体   繁体   中英

How to install sqlite3 for python3.7 in seperate directory on linux without sudo commands?

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!

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 !

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM