导入数据库错误。对Pythonanywhere的Flask + SQLalchemy + SQLite部署失败

时间:2017-03-24 16:00:18

标签: python flask deployment wsgi pythonanywhere

无法在任何地方将python应用程序部署到python。按照他们的教程https://help.pythonanywhere.com/pages/Flask/

App.py位于此路径home/koti1/evo/app.py,database.py,models.py和所有其他文件也在那里。在localhost上一切正常。

pythonwnyehre上的设置:

 Source code:
/home/kotik1/evo

Working directory:
/home/kotik1/evo

WSGI配置文件:

import sys

path = '/home/kotik1/evo'
if path not in sys.path:
   sys.path.append(path)

from app import app as application

日志中的错误:

:Error running WSGI application
:ImportError: No module named 'database'
:  File "/var/www/kotik1_pythonanywhere_com_wsgi.py", line 7, in <module>
:    from app import app as application
:
:  File "./app/app.py", line 6, in <module>
:    from database import db_session

同样,localhost上的sqlite数据库没有问题。

有database.py文件包含这样的内容:

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    #gitcommen
    import models
    Base.metadata.create_all(bind=engine)

正如您从日志中看到的那样,来自init_db的{​​{1}}在database.py中被文件末尾的这些行调用。 :

app.py

错误在app.py中的导入行中,但是我无法弄清楚原因,因为在localhost上一切都很好并且安装了所有依赖项如sqlalhemy。可能是什么原因?

if __name__ == '__main__':
init_db()
app.run()

0 个答案:

没有答案