First push django in heroku - django

I'm trying to push my django app in heroku and I've followed all the instructions in the tutorial of heroku's page, but when i try to do the push i get this:
christian#christian-R480-R431-R481:~/Documentos/heroku/Portafolio6$ sudo git push heroku master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 542 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)
! Push rejected, no Cedar-supported app detected
To git#heroku.com:mysterious-thicket-1865.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:mysterious-thicket-1865.git'
christian#christian-R480-R431-R481:~/Documentos/heroku/Portafolio6$
I dont know why this happens. Do I have to do the push in the django project or when i have the virtualenv folder?

Do you have a valid requirements.txt file? This file is needed by Heroku to pip install the relevant python packages that your app uses.
To auto generate this file, just run the following code:
pip freeze > requirements.txt
The requirements.txt file should reside at the top most level, adjacent to the app.
The 'Step 3 - Heroku Best Practices' section at http://www.deploydjango.com/django_project_structure/ will give you more info.

Check that you have the requirements.txt, Procfile and runtime.txt files in your directory.
To generate requirements.txt, activate your virtualenv and freeze the installed packages:
workon my_project
pip freeze > requirements.txt
Your Procfile is responsible for telling the heroku system how to run your app (and most likely is what is missing in this instance). Here is a sample:
web: gunicorn my_project.wsgi -b 0.0.0.0:$PORT
Your runtime.txt file is responsible for determining which version of python to run:
python-2.7.4
Ensure that all three files exist (technically runtime.txt is optional, but it's a good idea), are commited and then try your push again.

Related

Fail to push to Heroku: /app/.heroku/python/bin/pip:No such file or directory

I am trying to push a Django project to Heroku, but it keeps telling me that the following:
/app/.heroku/python/bin/pip: No such file or directory
The complete error message is shown below. How can I address this issue? Do I need to first install pip on Heroku?
Counting objects: 451, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (383/383), done.
Writing objects: 100% (451/451), 1.07 MiB | 349.00 KiB/s, done.
Total 451 (delta 87), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.5.1
remote: -----> Installing pip
remote: -----> Installing requirements with pip
remote: /app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51
/bin/steps/pip-install: line 5: /app/.heroku/python/bin/pip: No such file or directory
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to rocky-tor-70537.
remote:
To https://git.heroku.com/rocky-tor-70537.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/rocky-tor-70537.git'
My requirements.txt file is empty, as shown below.
# this is for Heroku and other servers.
# Locally, you should install requirements_base.txt
-r requirements_server.txt
My requirements_server.txt is as follows:
-r requirements_base.txt
# packages that are unnecessary on Windows/Mac local dev environments, or don't install properly
psycopg2>=2.5.1
My requirements_base.txt is as follows:
appdirs==1.4.3
asgi-redis==0.14.1
asgiref==0.14.0
autobahn==0.16.0
Babel==2.3.4
boto==2.42.0
channels==0.17.3
colorama==0.3.7
contextlib2==0.5.4
coverage==4.2
daphne==0.14.3
dj-database-url==0.4.1
Django==1.8.8
django-countries==4.0
django-easymoney==0.7.1
django-floppyforms==1.7.0
django-idmap==0.4.1
django-vanilla-views==1.0.4
djangorestframework==3.4.6
honcho==0.7.1
huey==1.2.0
IPy==0.83
mock==2.0.0
msgpack-python==0.4.8
otree-core==1.2.8
otree-save-the-change==1.1.3
packaging==16.8
pbr==1.10.0
py==1.4.31
pyparsing==2.2.0
pytest==2.9.2
pytest-django==3.0.0
python-redis-lock==3.2.0
pytz==2016.6.1
raven==5.25.0
redis==2.10.5
requests==2.11.1
schema==0.6.2
six==1.10.0
Twisted==16.2.0
txaio==2.5.1
unicodecsv==0.14.1
whitenoise==3.2.1
ws4py==0.3.5
XlsxWriter==0.9.3
zope.interface==4.2.0
I ran into this issue recently and was able to adjust it by changing the python version in the runtime.txt.
Changing to
python-3.5.2
But based off your requirements that you have listed, it seems like you are never getting to the requirements_base.txt.
In your requirements_server.txt file, change it so that:
-r requirements_base.txt
is listed there.
I simply had two typos in my runtime.txt
Make sure it says python-3.6.1 and not Python-3.6.1 or python 3.6.1
The error message is pretty bad. May this post save someone 30 minutes.
Looks like Heroku now supports only 3.6.1 and 2.7.13 Python versions.
https://devcenter.heroku.com/articles/python-runtimes#supported-python-runtimes
If you are using the default heroku buildpack I would guess that the requirements.txt file in your project folder is missing.
I had the same problem on Ubuntu 16.04 and after manually installing Heroku CLI, using
wget https://cli-assets.heroku.com/branches/stable/heroku-REPLACE_ME_OS-REPLACE_ME_ARCH.tar.gz -O heroku.tar.gz
mkdir -p /usr/local/lib
tar -xvzf heroku.tar.gz -C /usr/local/lib
/usr/local/lib/heroku/install
it worked like a charm.
In the folder I have 4 files. One is python script, second is procfile (no extension) with content web: gunicorn skripta1:app. Third is requirements.txt with:
appdirs==1.4.3
bokeh==0.12.5
click==6.7
Flask==0.12.2
gunicorn==19.7.1
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
numpy==1.12.1
packaging==16.8
pandas==0.20.1
pandas-datareader==0.4.0
pyparsing==2.2.0
python-dateutil==2.6.0
pytz==2017.2
PyYAML==3.12
requests==2.14.2
requests-file==1.4.2
requests-ftp==0.3.1
six==1.10.0
tornado==4.5.1
Werkzeug==0.12.2
And fourth is runtime.txt with python-3.5.2
According to Heroku documentation, the only two officially supported python runtimes are 2.7.13, and 3.6.1.
I recently had the same issue with oTree deployment in heroku, but as soon as I changed runtime.txt to python-3.6.1 everything went smoothly.
Oh dear - I removed a blank line in my requirements/production.txt in order to try and change the line number and everything started working (or rather on to my next completely different error)
I ran into this same problem on Windows trying to deploy a Python app to Heroku. Turns out it was a file encoding problem. Depending on how you create Procfile, requirements.txt and runtime.txt your encoding may vary.
Assuming you're running Windows, use PowerShell. Get the following PowerShell Function and paste it in to your PowerShell console. Using this, you can check your file encoding:
get-fileencoding requirements.txt
If it comes back anything besides ascii that's probably the issue. In my case, my three files were all unicode. I just did this to force them to ASCII:
'python-3.6.1' | out-file -en ascii runtime.txt
You can also use an editor and then save the file using ASCII encoding.
Once I made this change to my Procfile, requirements.txt and runtime.txt I was able to successfully deploy to Heroku.
I was switching from app engine to heroku and had a setup.cfg file in the root directory with following content:
[install]
prefix=
It caused this issues while deployment. After removing everything went well.

Change path to manage.py when running Git Push Heroku Master

I just deployed Askbot forum to heroku successfully, but sometimes when running 'git push heroku master', the automatic collectstatic process fails (to me it looks like a random failure), prompting:
-----> Python app detected
-----> Installing dependencies with pip
Cleaning up...
-----> Preparing static assets
Collectstatic configuration error. To debug, run:
$ heroku run python ./askbot/setup_templates/manage.py collectstatic --noinput`
Well I don't really know if that's the problem, but the manage.py in .askbot/setup_templates/ contains the app's native version of the file, not the one I'm using for deployment, which is located in the app's root.
How could I make git push heroku master use the right manage.py file?
Change the path in your Procfile. Typically its something like this:
web: gunicorn hellodjango.wsgi --log-file -
Adjust it:
# from:
web: gunicorn .askbot/setup_templates/yourApp.wsgi
# to:
web: gunicorn .askbot/yourApp.wsgi
to check if the path was indeed your problem run this from the terminal:
heroku run python ./manage.py collectstatic
# or
heroku run python ./yourApp.wsgi collectstatic
Deleting or renaming Manage.py in askbot/setup_templates/ solved the problem.
Git Push Heroku Master never fails whan running collectstatic ever after.
so I believe that for some reason, probably because of sys.path configuration sometimes
Git Push Heroku Master first discovered and used ./askbot/setup_templates/manage.py instead of ./manage.py (which was the right one), and encountered an ImportError.

Manually remove Python package on Heroku

I was running heroku push master, and got this:
----- Python app detected
----- No runtime.txt provided; assuming python-2.7.3.
----- Using Python runtime (python-2.7.3)
----- Installing dependencies using Pip (1.2.1)
Downloading/unpacking Django-1.5c2 from https://www.djangoproject.com/download/1.5c2/tarball (from -r
requirements.txt (line 1))
Cannot determine compression type for file /tmp/pip-rYIGHS-unpack/tarball.ksh
Running setup.py egg_info for package Django-1.5c2
Installing collected packages: Django-1.5c2
Running setup.py install for Django-1.5c2
changing mode of build/scripts-2.7/django-admin.py from 600 to 755
changing mode of /app/.heroku/python/bin/django-admin.py to 755
========
WARNING!
========
You have just installed Django over top of an existing
installation, without removing it first. Because of this,
your install may now include extraneous files from a
previous version that have since been removed from
Django. This is known to cause a variety of problems. You
should manually remove the
/app/.heroku/python/lib/python2.7/site-packages/django
directory and re-install Django.
Successfully installed Django-1.5c2
How can I remove the previous Django package?
UPDATE:
My requirements.txt:
https://www.djangoproject.com/download/1.5c2/tarball/**#egg=django**
South==0.7.6
argparse==1.2.1
distribute==0.6.24
dj-database-url==0.2.1
psycopg2==2.4.6
wsgiref==0.1.2
PIL==1.1.7
The text in bold fixed the above warning.
UPDATE 2:
Since Django 1.5 was officially released, I just used pip freeze:
Django==1.5
South==0.7.6
argparse==1.2.1
distribute==0.6.24
dj-database-url==0.2.1
psycopg2==2.4.6
wsgiref==0.1.2
PIL==1.1.7
I've had problems where Heroku caches broken packages and there's no way to get them out. The Python buildpack should have some kind of support for flushing this cache (CACHE_DIR), but it does not.
There is a workaround: follow these instructions to change your Python runtime to, for instance, 3.3.0 (it doesn't matter if your app actually supports Python 3 or not). Then change it back to the default. The act of changing your Python runtime and then deploying will force the buildpack to totally erase the cache. As far as I know this is the only practical way to erase the cache at the moment.
Push current virtenv package to file
pip freeze > requirements.txt
Commit
git commit -am 'update packages'
And push to heroku
git push heroku
Then heroku will rebuild the environment
Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (13/13), 1.26 KiB, done.
Total 13 (delta 3), reused 0 (delta 0)
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.3.
-----> Preparing Python runtime (python-2.7.3)
-----> Installing Distribute (0.6.34)
-----> Installing Pip (1.2.1)
-----> Installing dependencies using Pip (1.2.1)
Downloading/unpacking Flask==0.9 (from -r requirements.txt (line 1))
Running setup.py egg_info for package Flask
Thought I removed the faulting package and all other packages that depends on it but nope. Each time I deploy I keep getting an error. Finally I somehow striped out all other packages that depends on the faulting package and everything worked perfectly. Hope somebody will find this useful

Unable to push Django project to Heroku

I am getting this error while pushing the Django project to Heroku master. I am new to Django. Any help will be really appreciated.
-----> Installing dependencies using Pip (1.2.1)
Downloading/unpacking Brlapi==0.5.5 (from -r requirements.txt (line 1))
Could not find any downloads that satisfy the requirement Brlapi==0.5.5 (from -r requirements.txt (line 1))
No distributions at all found for Brlapi==0.5.5 (from -r requirements.txt (line 1))
Storing complete log in /app/.pip/pip.log
! Heroku push rejected, failed to compile Python app
To git#heroku.com:enigmatic-plateau-3620.git
! [remote rejected] master -> master (pre-receive hook declined)
Use the --no-site-packages option to prevent the virtual environment from having access to all the packages on your system.
virtualenv --no-site-packages venv
If you don't need the Brlapi for your Django app, try removing the Brlapi==0.5.5 line from your requirements.txt document. Then, commit the change:
git add requirements.txt
git commit
git push heroku master

pip issue while deploying Django app to Heroku

I have an issue while trying to deploy my Django app to Heroku.
It complains about issues with installing facebook-sdk library, but actually there is
no such thing in the requirements.txt file.
I already tried pushing with -f flag, I commented out lines from requirements.txt. I've even pushed an empty requirements file and the issues still persist.
I have no idea if there is any way to reset the app or heroku's repo beside creating a new one? Any ideas what I could try?
Console log:
$ git push prod master
Counting objects: 52282, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (17957/17957), done.
Writing objects: 100% (52282/52282), 138.01 MiB | 137 KiB/s, done.
Total 52282 (delta 33410), reused 48501 (delta 30768)
-----> Heroku receiving push
-----> Python/Django app detected
-----> Preparing Python interpreter (2.7.2)
-----> Creating Virtualenv version 1.7
New python executable in .heroku/venv/bin/python2.7
Also creating executable in .heroku/venv/bin/python
Installing distribute.............................................................................................................................................................................................done.
Installing pip...............done.
Running virtualenv with interpreter /usr/local/bin/python2.7
-----> Activating virtualenv
-----> Installing dependencies using pip version 1.0.2
error: The requested URL returned error: 401 while accessing http://github.com/facebook/python-sdk.git/info/refs
fatal: HTTP request failed
Downloading/unpacking paramiko (from -r requirements.txt (line 17))
Creating supposed download cache at /app/tmp/repo.git/.cache/pip_downloads
Storing download in cache at /app/tmp/repo.git/.cache/pip_downloads/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fparamiko%2Fparamiko-1.7.7.2.zip
Running setup.py egg_info for package paramiko
Obtaining facebook-sdk from git+http://github.com/facebook/python-sdk.git#egg=facebook-sdk (from -r requirements.txt (line 23))
Cloning http://github.com/facebook/python-sdk.git to ./.heroku/src/facebook-sdk
Complete output from command /usr/bin/git clone -q http://github.com/facebook/python-sdk.git /tmp/build_1bn5oykhrmms7/.heroku/src/facebook-sdk:
----------------------------------------
Command /usr/bin/git clone -q http://github.com/facebook/python-sdk.git /tmp/build_1bn5oykhrmms7/.heroku/src/facebook-sdk failed with error code 128
Storing complete log in /app/.pip/pip.log
! Heroku push rejected, failed to compile Python/django app
The right solution is "Maxime R."'s solution on how to pip uninstall with virtualenv on heroku cedar stack?
heroku labs:enable user_env_compile heroku config:add
CLEAN_VIRTUALENV=true
Currently this won't work because there is a bug. You'll need to use
my fork of the buildpack until this get fixed upstream :
heroku config:add
BUILDPACK_URL=git#github.com:blaze33/heroku-buildpack-python.git
Now push your new code and you'll notice that the whole virtualenv
gets reinstalled.
Andrey's answer no longer works since March 23 2012. The new style
virtualenv commit moved the virtual env from /app to /app/.heroku/venv
but the purge branch wasn't updated to catch up so that you end up
with a virtualenv not being in PYTHONHOME.
After several attempts with heroku run command finally I applied Maxime R. solution successfully. Also I have been opened a Heroku ticket and Heroku support has been confirmed to me that this is the solution.
It's happen because you're using an empty repository for python-SDK's library (http://github.com/facebook/python-sdk.git), try using another repo: https://github.com/pythonforfacebook/facebook-sdk
I had removed two packages from the virtual env and requirements.txt, and temporarily changing the Python runtime (as suggested here) is the only approach I found that allowed me to uninstall those packages from heroku.