2

noob programmer here, I'm trying to get the SQLite3 on my Python installation up-to-date (I currently have version 3.6.11, whereas I need at least version 3.6.19, as that is the first version that supports foreign keys). Here's my problem, though: I have no idea how to do this. I know next to nothing about the command line, and I don't really know what files to replace (if at all) in my python install. And before anyone asks, I'm already using the latest Pysql version – it's what's not up to date. Can anyone give me some pointers, or maybe a guide on how to update this?

I'm on Mac OSX 10.5.8, working with python 2.6.

J.Swersey
  • 151
  • 3
  • 3
  • 16

5 Answers5

2

I suggest using the 'pip' command on the command line.

pip search sqlite
pip install pysqlite
muckabout
  • 1,923
  • 1
  • 19
  • 31
  • make sure to install setuptools. but pip is the preferred method to do this in python. or try 'easy_install pip' – muckabout Jun 05 '12 at 22:40
2

I just came fresh from installing this both in Mavericks and Mountain Lion.

This SO article mentions using the build_static method, which they say retrieves that latest version of the sqlite amalgamation. For some reason it didn't work (ie it didn't seem to download it or use it)

What I ended up doing was

  1. Downloaded pysqlite as a tarball
  2. Downloaded latest sqlite source amalgamation
  3. Unzipped pysqlite into its folder
  4. Unzipped sqlite and copied that to the pysqlite folder
  5. Opened setup.cfg and commented out all of the directives
  6. In Terminal, went to the pysqlite folder, and then:

$ python setup.py build_static install

This compiled pysqlite using the libraries from the latest sqlite sources. And then in Python, I used it as:

import pysqlite2.dbapi2 as sqlite3

Community
  • 1
  • 1
lernie
  • 21
  • 2
2

I recently installed python from source and used the following commands to install both SQLite from source and Python 2.7.13 from source.

for SQLite3 you can use the following commands $SQLITE_INSTALL_LOCATION

$ curl -O http://www.sqlite.org/sqlite-autoconf-3070603.tar.gz
$ tar xvfz sqlite-autoconf-3070603.tar.gz
$ cd sqlite-autoconf-3070603
$ ./configure --prefix=$SQLITE_INSTALL_LOCATION --disable-static CFLAGS="-g"
$ make && make install

Then when I compiled my python I edited the setup.py in the root of the Python source

$ curl -O https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
$ tar xvfz Python-2.7.13.tgz

Python-2.7.13/setup.py -- add the path to your SQLite install here: ```

...
# We hunt for #define SQLITE_VERSION "n.n.n"
# We need to find >= sqlite version 3.0.8
sqlite_incdir = sqlite_libdir = None
sqlite_inc_paths = [ '/usr/include',
                     '/usr/include/sqlite',
                     '/usr/include/sqlite3',
                     '/usr/local/include',
                     '/usr/local/include/sqlite',
                     '/usr/local/include/sqlite3',
                   $SQLITE_INSTALL_LOCATION/include,
                 ]
...

Once you've changed the setup.py in your python source finish up compiling and installing python assuming the install location is $PYTHON_INSTALL_LOCATION

$ cd  Python-2.7.13
$ LD_RUN_PATH=$SQLITE_INSTALL_LOCATION/lib ./configure --prefix=$PYTHON_INSTALL_LOCATION --enable-shared --enable-unicode=ucs4
$ LD_RUN_PATH=$SQLITE_INSTALL_LOCATION/lib make 
$ LD_RUN_PATH=$SQLITE_INSTALL_LOCATION/lib make install

Once you do that you should have a Python version with SQLite3 support installed at $PYTHON_INSTALL_LOCATION/bin/python

Hope this helps!

asampat3090
  • 115
  • 3
  • 5
0

Disclaimer: I'm not a Mac User, but by common knowledge i give you this info.

You could follow the next instructions:

Use Homebrew

As this page mention: If you need to upgrade sqlite, you could use Homebrew.

Homebrew implies an aditional "software manager". So you should know how to use it before.

Install it from the source

As this page metion:

  1. Download the sqlite-autoconf package
  2. Compile it and install it:

:

$ tar xvfz sqlite-autoconf-3071502.tar.gz
$ cd sqlite-autoconf-3071502
$ ./configure --prefix=/usr/local
$ make
$ make install

Either Homebrew or Source, verfy it

>>> import sqlite3
>>> sqlite3.version_info
(2, 4, 1)
>>> sqlite3.sqlite_version_info
(3, 6, 11)

>>> from pysqlite2 import dbapi2 as sqlite3
>>> sqlite3.version_info
(2, 5, 5)
>>> sqlite3.sqlite_version_info
(3, 6, 18)

Maybe you need to uninstall previous version of pysqlite. In any way, you should read this answer to understand better the sqlite/python relationship.

Community
  • 1
  • 1
jgomo3
  • 1,153
  • 1
  • 13
  • 26
-1

https://pip.pypa.io/en/latest/installing.html

python get-pip.py

python [complete path]

python c:\folder\get-pip.py