Home Download Buy Blog Forum Support

sqlite3 module in ST3

sqlite3 module in ST3

Postby gregor.hoch on Fri Feb 01, 2013 9:26 pm

Hi,

ST2 shipped with a trimmed down standard library that excluded the sqlite3 module. On Mac OS, however, I was able to import the sqlite3 module because ST relied on the system version of Python. ST3 bundles Python 3.x on Mac OS and I am unable to import sqlite3. Is there any word on that problem? How can I circumvent the problem?

This error comes up when I try `import sqlite3` in the ST3 console:
Code: Select all
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "X/sqlite3/__init__.py", line 23, in <module>
  File "X/sqlite3/dbapi2.py", line 26, in <module>
ImportError: No module named '_sqlite3'
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: sqlite3 module in ST3

Postby jps on Sat Feb 02, 2013 1:55 am

It's not compiled in. I'd like to add it, but it's not currently a high priority, and compiling custom versions of Python is a challenging and time consuming task.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: sqlite3 module in ST3

Postby FichteFoll on Sat Feb 02, 2013 2:42 am

If you want to use that plugin for your very own you probably could extend `sys.path` to the modules path from your local Python distribution and import modules from there, too.
FichteFoll
 
Posts: 313
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: sqlite3 module in ST3

Postby gregor.hoch on Sat Feb 02, 2013 5:10 pm

That might be a good solution. I am still having problems with it though.

1) Not really essential but: Why don't I simply get an "No module named 'sqlite3'" if sqlite3 is not included? Instead I get the error posted above.

2) When I first add the modules path from your local Python distribution to ST3 and then try to import 'sqlite3', I still get an error (see below). In my case the path is '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3' (PATH variable below).

Code: Select all
import sys
sys.path.insert(0, PATH)
import sqlite3

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/sqlite3/dbapi2.py", line 26, in <module>
    from _sqlite3 import *
ImportError: No module named '_sqlite3'
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: sqlite3 module in ST3

Postby gregor.hoch on Sat Feb 02, 2013 8:16 pm

okay, problem solved. On Mac OX, the code below allows you to import sqlite3 by adding the modules path from your local Python distribution to `sys.path`. The example uses the location on my system. You can find out which one is the correct location on your system by importing `import sqlite3` and `import _sqlite3` in your system python and then running `print(sqlite3.__file__)` and `print(_sqlite3.__file__)`. `import sqlite3` works afterwards but maybe the additions to the search path are problematic down the road. I haven't tested this solution enough.

Code: Select all
sys.path.insert(0, '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload')
sys.path.insert(0, '/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3')
import sqlite3
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: sqlite3 module in ST3

Postby gregor.hoch on Sat Feb 02, 2013 8:28 pm

and if you want to package it, simply copy the `sqlite3` folder from `/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3` to your ST3 package folder and add `_sqlite3.so` from `/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload` to that folder. Now you should be able to import sqlite3 from your package without messing with the `sys.path`.
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm

Re: sqlite3 module in ST3

Postby gregor.hoch on Mon Feb 04, 2013 3:55 am

My last solution actually does not work for sqlite3 because '_sqlite3' doesn't get imported (when I tried earlier, the additional path were still part of sys.path). So you can do this:
1) copy the `sqlite3` folder from `/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3` to your ST3 package folder
2) begin your plugin with
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload')
import sqlite3

This works on my machine but doesn't seem to be a good solution for packaging!


Any solution to include '_sqlite3.so' as part of the plugin files to that `import _sqlite3`?
(`import sqlite3` fails because of the problem with `import _sqlite3`)
gregor.hoch
 
Posts: 128
Joined: Sat Oct 01, 2011 7:54 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests