我自己创建了一个包含sqlite3数据库的包。我使用python flask框架进行后端编程,我可以不受任何限制地使用我的包。
import sqlite3 as lite
import os
dir_path = os.path.dirname(os.path.abspath(__file__))
db_file = os.path.join(dir_path, 'szs.db')
class Database:
def __init__(self):
self.con = lite.connect(db_file)
...
但是,一旦我在heroku
部署我的烧瓶项目,它使用我的包与sqlite3数据库,我得到以下错误:
2015-10-11T19:53:35.403525+00:00 app[web.1]: __import__(module)
2015-10-11T19:53:35.403526+00:00 app[web.1]: File "/app/app/__init__.py", line 8, in <module>
2015-10-11T19:53:35.403528+00:00 app[web.1]: from .concrete import concrete
2015-10-11T19:53:35.403530+00:00 app[web.1]: from .views import concrete
2015-10-11T19:53:35.403529+00:00 app[web.1]: File "/app/app/concrete/__init__.py", line 7, in <module>
2015-10-11T19:53:35.403532+00:00 app[web.1]: File "/app/app/concrete/views.py", line 5, in <module>
2015-10-11T19:53:35.403533+00:00 app[web.1]: from .forms import BendingForce, ShearForce, Profile
2015-10-11T19:53:35.403534+00:00 app[web.1]: File "/app/app/concrete/forms.py", line 119, in <module>
2015-10-11T19:53:35.403536+00:00 app[web.1]: sizes = [(j, j) for j in Database().select_col('IPE', 'size')]
2015-10-11T19:53:35.403537+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.4/site-packages/civeng/steel/szs.py", line 38, in select_col
2015-10-11T19:53:35.403538+00:00 app[web.1]: cur.execute('SELECT '+col+' FROM '+table+'')
2015-10-11T19:53:35.403539+00:00 app[web.1]: sqlite3.OperationalError: no such table: IPE
2015-10-11T19:53:35.403546+00:00 app[web.1]: [2015-10-11 19:53:35 +0000] [8] [INFO] Worker exiting (pid: 8)
2015-10-11T19:53:35.551918+00:00 app[web.1]: [2015-10-11 19:53:35 +0000] [3] [INFO] Shutting down: Master
2015-10-11T19:53:35.551994+00:00 app[web.1]: [2015-10-11 19:53:35 +0000] [3] [INFO] Reason: Worker failed to boot.
2015-10-11T19:53:36.431233+00:00 heroku[web.1]: State changed from starting to crashed
2015-10-11T19:53:36.409628+00:00 heroku[web.1]: Process exited with status 3
2015-10-11T19:53:55.196843+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=probus.herokuapp.com request_id=48aa4176-88f8-456f-ac86-bba688e4215f fwd="178.199.176.52" dyno= connect= service= status=503 bytes=
似乎是什么问题?与数据库文件的连接错误了吗?
答案 0 :(得分:0)
我明白了。问题是包裹。数据库文件未随附。所以我必须将以下行添加到我的设置文件中:package_data={'civeng/steel': ['szs.db'],}
from setuptools import setup
setup(name='civeng',
version='0.2.7',
description='civil engineering tools',
url='https://pypi.python.org/pypi/civeng',
author='author',
author_email='author@email.com',
license='GPLv3',
packages=['civeng',
'civeng/concrete',
'civeng/concrete/modules',
'civeng/steel',
'civeng/steel/modules',],
package_data={'civeng/steel': ['szs.db'],},
zip_safe=False)