Error while deploy my django website on heroku - python

I created a personal portfolio website using django and it also includes a blog. You can see the exact directory listing and source code in my github repository by clicking here
I have the procfile and the requirements.txt files as said in the heroku website and did the following in command prompt as directed by heroku :
$ heroku login
$ heroku git:clone -a appname
$ cd appname
$ git add .
$ git commit -am "make it better"
$ git push heroku master
Now I see the following error while deploying and the push fails :
Warning: Your application is missing a Procfile. This file tells Heroku how to run your application.
Yes there is a procfile in the directory though.
Please help me deploy this website in heroku.

Your file is called Procfile.txt. It should be called just Procfile.

It might be that you made a .txt file instead of a non-extension one or that you named it procfile and not Procfile. Heroku is sensitive about capitalisation.

Related

Flask app works locally, fails on heroku. Procfile and requirements.txt didn't do it..?

Started going a bit mad on this, hence first post.
I have yet to deploy an app public facing for others to use. They launch locally just fine..
How can I get this app to deploy on Heroku?
Here is my repository: https://github.com/codereyes-1/tesseract_flask_new
I wrote a python app in Flask that makes a call to google tesseract function. The app works locally but fails in Heroku.
There is no Flask build pack I can find. Some research returned "add a requirements.txt and Profile" but that didn't work.
Here is the build log from Heroku:
"
Building on the Heroku-20 stack
-----> Using buildpack: heroku/python
-----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
! Push failed
"
¯\(ツ)/¯
This is what you will need to do to deploy your app to Heroku:
Login to heroku on your terminal ($ heroku login)
Ensure your application is in a git repository ($ git remote -v)
Create a Heroku application ($ heroku apps:create my_app-app)
Create Postgres database ($ heroku addons:add heroku-postgresql:hobby-dev)
Log errors to STDOUT
Set environment variables in Heroku ($ heroku config:set LOG_TO_STDOUT=1 # Add others if you have them)
Install gunicorn and psycopg2 ($ pip3 install gunicorn psycopg2)
Add Procfile to root directory and update it ($ touch Procfile)
Update your requirements.txt (pip3 freeze > requirements.txt)
Commit your changes ($ git commit -m '<your-commit-message>')
A remote Heroku repository ($ heroku git:remote -a <your-heroku-app-name>)
Push to Heroku ($ git push heroku master)
I was missing "web: gunicorn app:app" in my Procfile, I matched python to supported versions in runtime.txt.App launches correctly with these settings.
#BeppeC #Still_learning #Gitau Harrison Thank you all for your help. I got the app deployed, and I learned how to deploy my other apps as well. 🤜🏽🤛🏽

Deploying Flask application written in one file to Heroku

I've built a flask app and I tread to deploy it on Heroku but I got this error:
(venv) MacBook-Pro-alkhas-b-shosha:myApp joodi$ git push heroku master
error: src refspec master does not match any.
error: failed to push some refs to 'https://git.heroku.com/<app-name>.git'
I think the problem because I wrote all the application on one file.
This my app structure:
all Flask code is in flasker.py.
So when I start writing on Procfile I got confused, I didn't know what I supposed to write on it, here what I wrote
web: gunicorn myApp:app
What can I do without changing the structure?
There are a couple of issues here.
Git issue
error: src refspec master does not match any.
It looks like you haven't committed any code (Git can't find a master branch on your local system). git push operates on commits, not files.
Make sure to commit your code locally before trying to push to Heroku.
Procfile issue
Also, update your Profile to point to your flasker.py file. Assuming your Flask object is called app:
web: gunicorn flasker:app
Your error message hints to you not being on the master branch.
Try this:
git push heroku your_branch:master

Heroku App Not Compatible with Python Buildpack

I'm trying to deploy a Django/Python application that runs locally, but will not deploy to Heroku. When trying to deploy, I receive the error:
App not compatible with buildpack: https://codon-
buildpacks.s3.amazonaws.com/buildpacks/heroku/python.tgz
I've tried multiple solutions to this issue. Currently my build pack is set to the Python build pack. (heroic build packs returns heroku/python). I have a Procfile, requirements.txt, runtime.txt, and Pipfile.lock, all of which usually resolve this issue.
Procfile:
web: gunicorn foodForThought.wsgi:application --log-file -
requirements.txt:
Django==1.11.8
pytz==2017.3
runtime.txt:
python-3.6.0
Pipfile.lock:
[requires]
python_full_version = "3.6.0"
All the aforementioned files are located in my home directory, and I'm also working in a virtual environment. Why is this error occurring?
So here's what I've come up with. I was also stuck with this problem until I found this command.
heroku buildpacks:add --index 1 heroku/python
The trick is to add this buildpack before you commit to the Heroku git repo. You can follow the steps like so:
git add .
git commit -am "First Commit"
heroku git:remote -a yourapp
heroku buildpacks:add --index 1 heroku/python
git push heroku master
I found this through the Heroku docs!

webpack and django on Heroku: bundling before collectstatic

I am building a django+react app on Heroku, using django-npm which automatically installs all modules from package.json to node-modules dir and then copies everything to staticfiles/ during python manage.py collectstatic (which is triggered by Heroku during deploy).
However, for this configuration to work I need to pre-bundle my React app before deployment and put it into my static folder along with all the CSS, fonts, etc. to be picked up by collectstatic later.
But I don't want to pollute my git diffs with new bundle versions. So, is there a way to make webpack create a bundle during deployment?
I know there is a release command on Heroku where I can put my npm run build. But the problem is it only fires AFTER collectstatic, so my bundle will only be created in static/ folder after this folder is scanned, and won't get copied to staticfiles dir.
Update:
Using bin/pre_compile should no longer be necessary as of March 11, 2019. Heroku will now automatically call an app's build script (if defined in package.json) during Heroku's build process. Source: Heroku Changelog.
Original: You can accomplish this with the (undocumented) pre_compile hook exposed by the heroku/python buildpack.
Add an executable shell file named bin/pre_compile at the top level of your app and it will be called automatically as part of the build process.
cd my-django-app
mkdir bin
echo '#!/usr/bin/env bash' >> bin/pre_compile
echo 'npm run build' >> bin/pre_compile
chmod +x bin/pre_compile

Deploying a simple python script to Heroku without Flask or Django

I'm trying to deploy a python script, but I get this error
Failed to detect app matching https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/python.tgz buildpack
What files I have right now:
automation.py
A simple python script which imports praw, time, os and inspect.
requirements.txt
As described in the Heroku documents, I have created this file by running pip freeze > requirements.txt, containing:
astroid==1.5.2
colorama==0.3.8
isort==4.2.5
lazy-object-proxy==1.2.2
mccabe==0.6.1
praw==4.4.1.dev0
prawcore==0.10.1
pylint==1.7.1
requests==2.13.0
six==1.10.0
update-checker==0.16
wrapt==1.10.10
runtime.txt
Again as described in Heroku documents, this file contains the runtime for my script, containing:
python-3.6.0
I have changed my remote to heroku, added all files, commited and pushed to heroku master, but I get the error mentioned in the beginning. Is there something I'm doing wrong? I have seen this answer, but I'm not convinced. Would like to avoid any frameworks if possible.
git ls-files output
.gitignore
LICENSE
README.md
requirements.txt
runtime.txt
automation.py
In addition to runtime.txt and requirements.txt, a Procfile is required - that's how Heroku knows what script to run for your app. Without it, Heroku doesn't know automation.py is anything special. Note though - if your script doesn't listen on any port, define the process name as "worker" or anything other than "web". If you define it as "web" Heroku will expect it to bind to an externally visible port (not on localhost). If Heroku doesn't detect a port bind within 60 seconds, it reports the app as failed to start

Categories