Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sqlite3 with IronPython 2.6 for .Net4

i'm working with SharpDevelop 3.2.0, IronPython 2.6.1 for .Net4.

To have access to the sqlite3 functionality using this module for IronPython: IronPython.SQLite

My program is an GUI application and access an sqlite database. When starting the program via ipy.exe interpreter from IronPython everything (included the database access) works just perfect.

But if i try to start the program i compiled with SharpDevelop to an executable, i get the exception:

IronPython.Runtime.Exceptions.ImportException: No module named _sqlite3

The reason for this exception is located in dbapi2.py:

from _sqlite3 import *

On IronPython console, i can import _sqlite3 and use it as intended.

I already gave SharpDevelop the paths to the sqlite3 module, but there is no file named _sqlite3 anywhere in IronPython or the sqlite3-module folder.

Please tell me what could cause this trouble when building a compiled version of my program.

Thank you very much.

like image 650
user384651 Avatar asked Aug 18 '10 15:08

user384651


2 Answers

There is no _sqlite3 file anywhere; IronPython.Sqlite.dll provides a module called _sqlite3.

If you follow the website instructions and put IronPython.Sqlite.dll in the DLLs folder, that's probably why it doesn't work under SharpDevelop. When running ipy.exe, it implicitly adds a reference to any DLL in the DLLs folder. When SharpDevelop builds an executable, it's a small stub that runs IronPython, but it doesn't know about any installed versions of IronPython and thus won't load anything from the DLLs folder.

Your best is to modify your main script to include

import clr
clr.AddReference("IronPython.SQLite.dll")

and then make sure that IronPython.SQLite.dll is in the same directory as the exe. This is my preferred option anyway, and I should add it to the instructions when I get a chance.

like image 58
Jeff Hardy Avatar answered Sep 29 '22 01:09

Jeff Hardy


I already expected you telling me to reference somehow to the DLL.

After a few failures i was able to compile the program successfully, but it was a bit more tricky to include the DLL.

  1. I added the DLL into SharpDevelop References.
  2. I had to add following code to my script:

import sys import nt import clr sys.path.append(nt.getcwd()) clr.AddReferenceToFile('IronPython.SQLite.dll')

This was necessary to point to the DLL in my execution directory.

Thank you very much for your help.

like image 41
user384651 Avatar answered Sep 29 '22 01:09

user384651