I have a Flask app which runs fine locally with Heroku. However when I try git push heroku master I get the error No default language could be detected for this app.
Setting the buildpack manually with heroku buildpacks:set heroku/python and then trying to push also gives an error: Failed to detect app matching https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/python.tgz buildpack.
Is this error because I have file types other than Python in my project? The project structure is below, and the data folder contains several different file types.
app/
data/
model/
utils/
static/
css/
templates/
Procfile
README.md
requirements.txt
runtime.txt
run.py
If so, what's the recommended course of action here?
For some reason when I switched to master branch I was able to push successfully.
Related
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
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
First time using Heroku. Trying to push. I have run the command:
heroku create --buildpack heroku/python
and it displayed
$ heroku create --buildpack heroku/python
Creating app... done, glacial-reef-7599
Setting buildpack to heroku/python... done
https://glacial-reef-7599.herokuapp.com/ | https://git.heroku.com/glacial-reef-7599.git
Stack trace:
$ git push heroku master
Counting objects: 129, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (124/124), done.
Writing objects: 100% (129/129), 69.06 KiB | 0 bytes/s, done.
Total 129 (delta 22), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to pure-badlands-9125.
remote:
To https://git.heroku.com/pure-badlands-9125.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/pure-badlands-9125.git'
I've gotta be missing something.
I have added a requirements.txt to my root directory. It looks like this:
.git
.idea
projectapp
projectname
rango
db.sqlite3
manage.py
populate_rango.py
requirements.txt
Quick Solution
Goto heroku dashboard (https://dashboard.heroku.com/)
go inside app/project
click setting
scroll down little bit and click add build pack
select your desired buildpack (in my case i have selected heroku/nodejs).
TLDR;
Actually what heroku does is, it tries to identify what project you are deploying by looking at files in your project, such as if your project have package.json file it understands it is a nodejs project, if your project have requirements.txt file it understands it is a python project and so on, see this document to see to know what languages you can run on a heroku server
as you know to run a specific project such as a nodejs project in a computer node runtime must be installed in that computer otherwise you can not nodejs app in the computer, what heroku does it runs each of your app in a different container, it means in one container it is only one app is running and of course that container have installed nodejs, so if a container runs only one app it doesnt make sense to install all other runtimes in the container so container have only one runtime in my case it is nodejs. they have ofcourse other type of containers such as one type for python and that container have installed python runtime(of a specific version) so if my app gets installed in python container it will not work because my app in in nodejs. for this very reason somehow we need to identify the type of app in beginning to choose correct container type, mostly heroku automatically detect it but if it is failed to detect you have to tell explicitly either by going to their dashboard settings or through runtime file in your project, and as you may have noticed you have do this only once.
For future references, you must ensure that you are pushing the branch with your code to heroku master.
If you branched from your master branch and all your code is on a, say, develop, push that to the heroku master.
So instead of:
git push heroku master
You would do something like:
git push heroku develop:master
This question has important details on this How to push different local Git branches to Heroku/master
When deploying using Docker, ensure to set the stack of the app to container, as shown in the docs:
heroku stack:set container
You need to create a runtime.txt file. On the command line, in the same folder as your requirements.txt file, enter echo "python-3.5.1" > runtime.txt. Of course, make sure to switch the 3.5.1 with whichever version of Python you are using.
I can't remember how I fixed this but looking at the Date Modified in my files after I posted this question I created two files:
runtime.txt (thanks rurp) which contains:
python-3.5.2
Procfile which contains:
web: gunicorn projectname.wsgi --log-file -
This is a Django project and projectname.wsgi leads to a wsgi.py located at
projectname/wsgi.py
This contains:
import os
import signal
import sys
import traceback
import time
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectname.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
I had the same problem even after including runtime.txt. What worked was the inclusion of the requirements.txt
In my case I was in a sub git folder. When I looked at the root .git folder - the project indeed didn't had a package.json file - so heroku could not identify the webpack
I was running a django project and for me none of the solution above worked. So finally I gave up and went to the path thats mentioned in the error and it clearly stated that heroku needs either of the below file to detect a django project:
requirements.txt
setup.py
Pipfile
I than created a requirements.txt file by copying the contents of pip freeze in the root of the project and it worked correctly.
Faced this issue today and released I had named my requirements.txt as requirements.txt.txt(I literally named the file with .txt extension when it was already a text file), I also had a runtime.txt file with the content python-3.8.7.
Renaming the requirements.txt file correctly solved my issue.
I had 3 files in my root folder: code.py, requirements.txt and runtime.txt
Adding requirements.txt even as a blank text file did the trick for me, and I also ensured there was no build pack Heroku had added.
Heroku’s Python support extends to the latest stable release from the Python 2.x and Python 3.x series.
Today, this support extends to these specific runtimes:
python-2.7.13
python-3.6.1
try to change your python version in runtime.txt
Create Pipfile file in root folder and add python version and packages required for application. check sample file here
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
[packages]
django = "*"
gunicorn = "*"
django-heroku = "*"
[requires]
python_version = "3.6"
Also check Configuring Django Apps for Heroku
One more thing to note is to actually commit your changes to your git repo, before you can push them to Heroku.
You might have a requirements.txt setup locally, but if it's not committed to your repo, git push heroku master will not be able to locate it.
If you've tried some of the above answers and the problem still persists;
Ensure you are git "committing" in the right directory.
For instance, if your file structure is as follow:
/src
/...
manage.py
.gitignore
Pipfile/requirements.txt
Pipfile.lock
Procfile
runtime.txt
Ensure you're git adding, committing, pushing etc. from the root directory. Since we work mostly in the src/ or main_app_directory/ we tend to forget to change directory back to root before committing.
Hey guys so I have been stuck on this issue for the past two days and I found the solution to my problem. The first fix was renaming
"requirement.txt" to "requirements.txt"
then I removed the runtime.txt
cleared buildpacks using heroku cli set the buildpack to python
heroku buildpacks:set heroku/python
and Boom! it got uploaded an everything works now
I installed heroku plugin called heroku-push. And I deployed my app with heroku push --app appname. I have settings.py and local_settings.py and in settings.py file DEBUG is False but in local_settings.py file DEBUG is True. And I included local_settings.py in .gitignore file. When I open my page in browser there is a message telling me DEBUG=True. Say that If local_settings.py also is deployed to server, there is a code in settings.py file
try:
from .local_settings import *
except ImportError:
pass
What should I do? Heroku gives me git#heroku.com:appname.git But I can not view it or clone it. It gives me empty folder.
If you create .gitignore file (if you didn't: touch .gitignore)
Now open .gitignore with your favorite text editor and paste in the following information about files Git should ignore:
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
I advise you to read this tutorial on medium it helped me to deploy my first django app :
https://medium.com/#BennettGarner/deploying-django-to-heroku-procfile-static-root-other-pitfalls-e7ab8b2ba33b
After successfully deploying a test app using the steps outlined here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_flask.html
I tried to deploy my actual flask application which has the following structure:
myApp/
runServer.py
requirements.txt
myApp/
__init__.py
helpers.py
clean.sh
static/
myApp.css
handlers/
__init__.py
views.py
templates/
layout.html
viewOne.html
viewTwo.html
Where views.py contains my url mappings.
I have tried initializing the eb instance in the root directory as well as within the myApp module and git aws.push but I get the following error on the AWS dashboard:
ERROR Your WSGIPath refers to a file that does not exist. and the application does not work (404 for any path).
How can I deploy the above Flask application to elastic beanstalk?
I encountered a similar problem deploying a Flask application to EB, with a similar directory structure, and had to do 2 things:
Update my manage.py to create an object of name application, not app
import os
from application import create_app, db
from flask.ext.script import Manager, Shell
application = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(application)
Create .ebextensions/myapp.config, and define the following block to point to manage.py
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: manage.py
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "application/static/"
This let Elastic Beanstalk find the application callable correctly.
This is described briefly at the official docs, and is described in more detail in this blog post
EDIT - see project structure below
ProjectRoot
.ebextensions
application.config
application
main
forms.py
views.py
static
templates
tests
manage.py
requirements.txt
config.py
etc, etc
Add the following to .ebextensions/<env-name>.config:
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: myApp/handlers/views.py
Update:
If you don't have .ebextensions directory, please create one for the project. You can find more information of what can be done regarding the container configuration in Customizing and Configuring AWS Elastic Beanstalk Environments guide.
Your WSGIPath refers to a file that does not exist.
This error appears because Beanstalk, by default, looks for application.py. Check at Beanstalk web UI, Configuration > Software Configuration, WSGIPath is mapped to application.py
Update the WSGIPath as shown in the previous replies or rename to application.py file.
As of awsebcli 3.0, you can actually edit your configuration settings to represent your WSGI path via eb config. The config command will then pull (and open it in your default command line text editor, i.e nano) an editable config based on your current configuration settings. You'll then search for WSGI and update it's path that way. After saving the file and exiting, your WSGI path will be updated automatically.
WSGI configuration was painful for me. I did changed WSCI settings using eb config command but it did not work. Below you can fix this in 5 easy steps.
1- Moved app.py function to the root of the directory (where I runned eb init command.
2- Also renamed app.py as application.py and in that initilized application as application = Flask(__name__) not app = Flask(__name__)
3- eb deploy did not worked after this (in the same project) I tried to fix config by using eb config but it was too hairy to sort it out. Delete all .extensions, .gitignore etc from your project.
4- re initialize your project on EB with eb init and follow the prompts. when deployment is done, eb open would launch your webapp (hopefully!)
When I encountered this problem it was because I was using the GUI to upload a zip of my project files. Initially I was zipping the project level directory and uploading that zip to EB.
Then I switched to simply uploading a zip of the project files themselves-ie select all files and send those to a zip-and then the GUI upload utility was able to find my application.py file without a problem because the application.py file was not in a subfolder.
Well, In my case I followed the entire process and conventions but was still getting 404. The problem was my virtual environment. I was ignoring all environment config related folders/files in my .gitignore but not in .ebignore. After creating .ebignore and ignoring all the folders/files which were not related to project code, fixed the issue.