Import sqlite3 from Python2.7 to Heroku

I am trying to use Heroku with Python, I have successfully executed "hello word" with Flask .

Now I want to deploy a very basic application using sqlite3 and Flask, and I know that the application works. But it’s hard for me to make it work, and I suspect that the problem is sqlite related.

When I launched the Python shell that Heroku provides, here is 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 requirements.txt , the file used for dependencies? It contains only Flask==0.8 . Importing date and time into examples works as expected. I watched using heroku logs and this message also appears without any other important messages.

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

+6
source share
1 answer

This is not possible for Heroku, since sqlite requires a persistent writable file system. Since Heroku does not provide a persistent writable file system, sqlite3 will not work.

Something to keep in mind: Heroku is a distributed environment. This means that the application can run on many machines in many processes. In your case, this would create multiple instances of sqlite3 (each of which was executed locally), if that were allowed.

Also see: Heroku Devcenter - a read-only file system

+1
source

Source: https://habr.com/ru/post/898621/


All Articles