问题
I'm trying to deploy a fairly basic app with Heroku, and I've been successful before, but for some reason I'm getting an import error when I try now. Foreman start works with no issues, but when I try to start the application up, something seems to happen that breaks imports. This is the log message I get:
heroku[web.1]: Starting process with command `python manage.py runserver -p 40309`
app[web.1]: Traceback (most recent call last):
app[web.1]: File "manage.py", line 6, in <module>
app[web.1]: ImportError: No module named SpoolEngine
app[web.1]: from SpoolEngine import app
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=tranquil-taiga-1563.herokuapp.com fwd="66.31.20.171" dyno= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=tranquil-taiga-1563.herokuapp.com fwd="66.31.20.171" dyno= connect= service= status=503 bytes=
This is my Procfile:
web: python manage.py runserver -p $PORT
and this is the manage.py
file I'm using to start everything up:
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from flask.ext.script import Manager, Server
from SpoolEngine import app
manager = Manager(app)
manager.add_command("runserver", Server(
use_debugger=True,
use_reloader=True,
host='0.0.0.0')
)
if __name__ == "__main__":
manager.run()
I'm sorry if this is something silly that I've done, but I'm pretty new to this realm and would really appreciate some pointers.
回答1:
Guessing here: your code shows
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
So locally you have some packages installed in manage.py's parent directory, but that's not the case in Heroku.
Just to debug, I would also add
import sys
print sys.path
to the very top of manage.py, and compare outputs. You can look for your modules in the output of the local run, and then heroku run bash
and look at what's in the directories printed by the remote run.
回答2:
I would bet it's because you're trying to run the built-in Flask development server instead of letting Heroku run it in their normal framework (which is gunicorn, I believe). You can't run both.
Try reading through these instructions again:
https://devcenter.heroku.com/articles/python
and try getting rid of the manage.py script - I don't think you need it.
来源:https://stackoverflow.com/questions/18037027/flask-app-failing-on-heroku-but-working-with-foreman