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.

Init()

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.

Can’t find Foreman

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

Sample Python code gives a 404 error

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.

Foreman found, but python code still does not run.

Don’t use gunicorn, so the contents of the Procfile should therefore be:

Push rejected, no Cedar-supported app, detected.

Did you create the requirements.txt file?

 Heroku deployed but app crashes with: “Web process failed to bind to $PORT”

Heroku assigns the PORT, so the Flask default PORT of 5000 cannot be used.  The python code should therefore be changed thus:

 No web processes running

I 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 run

to verify the web process is up.

Resynching a repository or setting up a new machine

re-synch with:

For 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:

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.

 

Tags: , , ,

Leave a Reply

You must be logged in to post a comment.