There is a sqlite3 library that comes with python 2.7.3, but it is hardly the latest version.
I would like to upgrade it within a virtualenv environment. In other words, the upgrade only applies to the version of python installed within this virtualenv.
What is the correct way to do so?
The below works for me, but please comment if there is any room for improvement:
Activate the virtualenv to which you are going to install the latest sqlite3
Get the latest source of pysqlite
package from google code: wget http://pysqlite.googlecode.com/files/pysqlite-2.6.3.tar.gz
Compile pysqlite
from source and together with the latest sqlite
database: python setup.py build_static
Install it to the site-packages directory of the virtualenv: python setup.py install
The above will actually install the pysqlite
into path-to-virtualenv/lib/python2.7/site-packages
, which is where all other pip-installed libraries are.
Now, I have the latest version of sqlite
(compiled into pysqlite
) installed within a virtualenv, so I can do: from pysqlite2 import dbapi2 as sqlite
I checked setting something like this, works:
export export LD_LIBRARY_PATH=$HOME/<your-sqlite-install-dir>/sqlite3/lib
I’ve added it next to the line export PATH
in the activate
file:
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
export LD_LIBRARY_PATH=$HOME/…/sqlite3/lib # <- Here
One can check it in either one of two ways.
From Python in the virtualenv, first do:
>>> import _sqlite3
>>> _sqlite3.__file__
'/usr/lib/…/_sqlite3.cpython-35m-i386-linux-gnu.so'
Then exit Python and run ldd
on the string returned:
$ ldd /usr/lib/…/_sqlite3.cpython-35m-i386-linux-gnu.so
> …
> libsqlite3.so.0 => /home/…/sqlite3/lib/libsqlite3.so.0
> …
Or alternatively, again in Python from the virtualenv:
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.21.0' # Was 3.11.8 before
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With