Setting up Heroku, Flask and Python on a Windows 7 PC

Following the steps on the Heroku site for getting started with python guide I ran into a few issue-ettes. Below are some scrappy notes that could be used to accompany the guide if you run into the same issues that I did.

Before using the quickstart guide on the Heroku site itself, you’ll need to have ssh-keygen installed. The Open-SSH package for Windows can be downloaded from here: http://sshwindows.sourceforge.net/download. On installation you don’t need the server component and the PATH variable should be updated automatically to include the location of \bin\ssh-keygen.exe. WARNING: My PATH was destroyed twice after installing SSH. I would back it up first!

Once the Heroku toolbelt is installed and you login for the first time, when prompted to generate an SSH public key, the process will find and run ssh-keygen.exe.

I followed the steps here suggested by Mark Rajcok: http://stackoverflow.com/questions/19078939/foreman-installed-by-heroku-toolbelt-on-windows-cant-be-found successfully to get Foreman working. Note also below the comment on running without gunicorn.

The main points for me were:

  • install Heroku to c:\heroku (nowhere else)
  • add C:\Heroku\ruby-1.9.2\bin to the PATH
  • I did not need to un/install Foreman or downgrade it from version 0.63

The hello world Python code here lacks code to run the app. This is not the complete solution with respect to a Heroku deployment — see further below.

import osfrom flask import Flaskapp = Flask(__name__)@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
app.run()
Foreman found, but python code still does not run.Don't use gunicorn, so the contents of the Procfile should therefore be:web: python hello.py
Did you create the requirements.txt file?pip freeze > requirements.txt
Heroku assigns the PORT, so the Flask default PORT of 5000 cannot be used.  The python code should therefore be changed thus:import os
from flask import Flask
app = Flask(__name__)@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
No web processes runningI did not realise that I need to start up the web service manually after each deployment. Running heroku ps:scale web=1 resolved the issue. You can then also runheroku psto verify the web process is up.
re-synch with:heroku git:remote -a HEROKU_APP_NAMEFor a new machine generate an ssh key and add to Heroku.  See https://devcenter.heroku.com/articles/keys. When I did this initially at the office I had lots of problems with permissions - i.e:C:\GitHub\hellonode>git push heroku master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The problem was that the key was being generated on my HOMEDRIVE (in my work this is F:\.ssh) but Heroku was looking in C:\Users\MYNAME\.ssh. Copying the id_rsa files from F:\.ssh to C:\Users\MYNAME\.ssh fixed the problem.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store