简体   繁体   中英

Pip installed dependencies not available to application file

I'm having problems getting dependencies installed on Heroku. I have a Python app that I want to deploy but every time I try and load the site I get ImportError's for both flask and sqlalchemy. I get these same errors if I run: heroku run python and try and import the modules interactively. I'm very puzzled and can't seem to solve this issue I was hoping someone else would know a solution. The details of the relevant files are down below.

Profile:

web: python app.py

requirements.txt:

Flask==0.9
Jinja2==2.6
SQLAlchemy==0.7.9
Werkzeug==0.8.3

app.py:

import os, flask, sqlalchemy
from gateway import server

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))

    server.app.run(host='0.0.0.0', port=port)

EDIT: I ended up restarting my application by following the Heroku instructions step-by-step and then copying over all my old code. This seemed to fix the problem for me so my problems seem to be a weird edge case.

I think your error may be in the "from gateway import server". It's not clear to me what that line's doing, and that code doesn't work when I try to run it locally on my machine.

Here's similar code, but in a format that's more familiar to me - I've deployed this to Heroku successfully in the past:

import os
from flask import Flask
from flask import render_template

app = Flask (__name__)

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Can you run this code locally?

Check the Heroku Flash tutorial

https://devcenter.heroku.com/articles/python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM