在 Heroku 上使用 Python2.7 导入 sqlite3
我正在尝试使用 Python 来使用 Heroku,我使用 Flask 运行了 "hello word" 示例 成功。
我现在想使用 sqlite3 和 Flask 部署一个非常基本的应用程序,并且我知道该应用程序正在运行。但我很难让它工作,我怀疑问题出在 sqlite 上。
当我启动 Heroku 提供的 Python shell 时,这里出现导入错误日志:
$ 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
>>>
我需要向用于依赖项的文件 requirements.txt
添加一些内容吗?到目前为止它只包含 Flask==0.8
。示例中的导入日期时间按预期工作。我查看了 heroku 日志
,也出现了此消息,没有任何其他重要消息。
我有办法在 Heroku 上使用 sqlite3 吗? 感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在 Heroku 上是不可能的,因为 sqlite 需要永久可写文件系统。由于 Heroku 不提供永久可写文件系统,sqlite3 将无法工作。
需要考虑的事情:Heroku 是一个分布式环境。这意味着应用程序可以在许多机器上的许多进程中运行。在您的情况下,如果允许的话,这将生成多个 sqlite3 实例(每个实例都在本地运行)。
另请参阅:Heroku Devcenter - 只读文件系统
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