sqlite3 with Ren'py

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

sqlite3 with Ren'py

#1 Post by trekopedia »

Hi everyone,

I'm having trouble getting Ren'py to work with sqlite3. Normally sqlite3 is included within standard Python but my understanding is that it has been omitted from Ren'py (presumably to keep the distribution packages smaller). Has anyone successfully installed / used sqlite3 with Ren'py? If so, I would very much appreciate some guidance! :-)

I've copied a Python 2.7 version of the sqlite package into a 'python-packages' directory within the 'game' directory. Here's my 'init python' block in a file called '01init.rpy':

Code: Select all

init python:
    import sqlite3

When I attempt to build the app, I get the following error:

###
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/01init.rpy", line 2, in script
init python:
File "game/01init.rpy", line 3, in <module>
import sqlite3
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 108: invalid continuation byte
###

If anyone could point me in the right direction, I would be extremely grateful.

Thanks in advance.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: sqlite3 with Ren'py

#2 Post by xela »

I am afraid that it may not be possible to do, you can't add C dependent modules to Ren'Py without rebuilding the engine which is insanely, incredibly, horribly complicated.

If one such a module is not shipped with Ren'Py, you either have to try and find a pure python implementation of the same, write one yourself, use something else entirely (JSON/XML/Python Dict? sql data is not horribly complicated to convert using a simple python interpreter).
Like what we're doing? Support us at:
Image

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: sqlite3 with Ren'py

#3 Post by trekopedia »

Hi xela -- thanks. I thought that might be the case. However, I had seen some comments by PyTom in the archives about copying sqlite3 into the project directory and thought I might have been overlooking something. I'll use JSON instead.

User avatar
carrot
Regular
Posts: 28
Joined: Fri Jul 28, 2017 7:43 am
Contact:

Re: sqlite3 with Ren'py

#4 Post by carrot »

Have you looked at PyDbLite?

It's mostly the same as sqlite3 API-wise, and is pure python, so should run fine in renpy.

User avatar
Kaji
Regular
Posts: 87
Joined: Thu Nov 17, 2022 10:17 pm
Github: Kaji01
Discord: Kaji#7767
Contact:

Re: sqlite3 with Ren'py

#5 Post by Kaji »

Apologies for necroposting, but it's a continuation of this discussion. Similar issue, can't get SQLite to work, so decided to take the suggestion to use PyDBlite. Downloaded it and installed it in the game folder in the same manner outlined above.

Importing it produces the following error: ModuleNotFoundError: No module named 'pkg_resources'

Skimming the results for that error message says it's because SetupTools isn't installed, so I found that package. I've tried installing it on my computer to no effect and directly putting it into the game/python-packages folder, still to no effect.

Is there some step in the process that I'm missing here? And along the same lines, is there a better way to integrate a database into the app?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]