Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import sqlite3 with Python2.7 on Heroku

I'm trying Heroku with Python, I ran the "hello word" example with Flask successfully.

I now want to deploy a very basic application, using sqlite3 and Flask, and I know the application was working. But I have trouble getting it to work, and I suspect the problem is with sqlite.

When I started the Python shell that Heroku provides, here the import error log:

$ heroku run python     
Running python attached to terminal... up, run.2
Python 2.7.1 (r271:86832, Jun 26 2011, 01:08:11) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3
>>>

Do I need to add something to the requirements.txt, the file used for dependencies? It only contains Flask==0.8 so far. Import datetime in examples works as expected. I looked with heroku logs and this message appears as well, without any other important messages.

Do I have any way to use some sqlite3 on Heroku? Thanks for help.

like image 960
Nicolas Paris Avatar asked Oct 04 '11 19:10

Nicolas Paris


1 Answers

This isn't possible on Heroku, as sqlite requires a permanent writable file system. Since Heroku does not provide a permanent writable file system, sqlite3 won't work.

Something to consider: Heroku is a distributed environment. This means an application may run on many machines within many processes. In your case, this would generate multiple sqlite3 instances (each running locally), were it permitted.

Also, see: Heroku Devcenter - Read-only Filesystem

like image 60
Derek Springer Avatar answered Sep 18 '22 19:09

Derek Springer