Problem building my app with Heroku

I am working on the Flask Deployment Setup video in Build Python Web Apps with Flask:

When I execute git push heroku master the build fails and I get the following error:

ERROR: Could not find a version that satisfies the requirement pywin32==300 (from -r /tmp/build_5ea387ff/requirements.txt (line 55)) (from versions: none)
e 55))
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy…
remote:
remote: ! Push rejected to calm-waters-76945.

When I type pip install pywin32 I get a message that says Requirement already satisfied: pywin32 in the python file structure.

Any ideas how to resolve this?

Hi there.

The issue is that the pywin32 library is a Windows-specific library, which allows you to access certain functionality in the Windows OS.

As far as I know, you can’t get pywin32 on the *nix OS which the Heroku dynos run - which is why your build is failing.

If you remove (either completely, or just comment it out) the requirement for pywin32 == 300 from your requirements.txt and re-push, hopefully the app will build. (You might have some other Windows-specific dependencies which could cause problems, though.)

Let us know if that works or not. :slight_smile:

Edit: Just tried installing pywin32 to a REPL and on Heroku, both of which are *nix, and no dice. If you’re comfortable enough with pip, you can remove the requirement for pywin32 and re-add it as a dev dependency which should stop it from breaking your build when you deploy to Heroku but allow you to install it on your Windows computer (which I presume you’re using to do the work?). :slight_smile:

Hi.

I tried removing the " == some #" for all the items in my requirements.txt file. It didn’t work. Then I removed pywin32 and it was able to build.

The app still doesn’t work. I ran “heroku logs --tail” and got this:

021-04-01T01:13:41.021990+00:00 heroku[router]: at=error code=H14 desc=“No web processes running” method=GET path="/" host=calm-waters-76945.herokuapp.com request_id=12036a16-9ee0-4ece-8aa3-fdaa51a6c58e fwd=“108.65.145.43” dyno= connect= service= status=503 bytes= protocol=https

2021-04-01T01:53:07.326488+00:00 heroku[router]: at=error code=H14 desc=“No web processes running” method=GET path="/" host=calm-waters-76945.herokuapp.com request_id=f534989e-99db-4b40-bacc-8c9fea917703 fwd=“108.65.145.43” dyno= connect= service= status=503 bytes= protocol=https

Any ideas how to address this problem? The app is working on my local machine so I’m not sure why it’s not working in heroku.

Generally, you wouldn’t do this. The purpose of the {dependency}=={version} lines in the requirements.txt is to pin your application to using the listed version of that dependency.

What you may find if you don’t specify the version, both whilst learning and if you go on to build apps that others will use, is that later versions than the one you used during development may contain “breaking changes”. If some functionality that you’ve assumed results in “A” gets changed to result in “B” in a later version, then pulling that later version will break your code.

Pinning the version you used to create the app means that your code can be installed, and run, anywhere and work how it did when you wrote it.

Yes, you’d need to completely remove the dependency on pywin32 for it to build on Heroku; there is no version of that library available that Heroku can pull and install. If it’s included in any form in your requirements.txt, it will break the build on Heroku.

Right, ok. I’ve watched the video, though I’ve not done the entire path so this might have been covered earlier…

I think that they’ve omitted a step which you may need to do.

I am presuming that you’ve completed the entire video, and so you have a Procfile in the directory which looks like this:

web: gunicorn app:app

The Procfile tells Heroku what process types you want to run, and what the command each of them should execute at launch is meant to be. In this case, we’re defining a web process which should run gunicorn app:app at boot.

What they don’t appear to have included is the step to scale up your web dyno so that your web process is running.

If you go to your app dashboard on Heroku, you should see the following section:

image

(Don’t worry that my web process is different to yours, this is a static HTML app I’m using as an example not a Python one. :slight_smile: )

In my example above, the dyno is already running - hence why it says “ON”. Yours may say “OFF”, in which case the following steps will fix it.

Click the “Configure Dynos” link, and you’ll be taken to this page:

Click the button with the pencil icon, and you’ll be able to toggle the dyno on or off. Switch it on, then click “Confirm”:

At this point, your web process will be running and should respond to requests.

If that’s not the problem (for example if your dyno is already running), let me know - but this doesn’t seem to be done in the video that I saw. (I didn’t go through it at 1x speed!)

I recreated the requirements.txt file and just commented out pywin32. It builds.

Looks like the dynos are on.

Now I’m getting a 500 Internal Server Error. The app works on my local machine so I’m not sure what is going on.

I would presume that when you load the Heroku app and get that error, the Heroku logs would have more information as to what’s gone wrong?

Looks like it’s related to sqlalchemy.

I tried this and it worked:

SQLALCHEMY_DATABASE_URI = environ.get(‘DATABASE_URL?sslmode=require’)
python - sqlalchemy.exc.NoSuchModuleError: Can’t load plugin: sqlalchemy.dialects:postgres - Stack Overflow

2021-04-01T23:51:44.566248+00:00 app[web.1]: raise exc.NoSuchModuleError(
2021-04-01T23:51:44.566248+00:00 app[web.1]: sqlalchemy.exc.NoSuchModuleError: Can’t load plugin: sqlalchemy.dialects:postgres
2021-04-01T23:51:44.568315+00:00 app[web.1]: 10.69.66.119 - - [01/Apr/2021:23:51:44 +0000] “GET / HTTP/1.1” 500 290 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36”
2021-04-01T23:51:44.746386+00:00 app[web.1]: 10.69.66.119 - - [01/Apr/2021:23:51:44 +0000] “GET /favicon.ico HTTP/1.1” 404 232 “https://calm-waters-76945.herokuapp.com/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36”
2021-04-01T23:51:44.746676+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=calm-waters-76945.herokuapp.com request_id=28d8e897-30d1-447a-a72c-d098e352a062 fwd=“108.65.145.43” dyno=web.1 connect=0ms service=2ms status=404 bytes=393 protocol=https