Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Django/Python 3.4 to Heroku

I am trying to deploy my first example app with Django/Heroku using the Django/Heroku Getting Started Tutorial.

My tools: Python 3.4 and Windows 7 PowerShell.

My challenge: deploying to Heroku fails and I am not sure why. Upon my first "git push" I saw that python-2.7.0 was used by default. I then added a runtime.txt (python-3.4.0) file in the app root.

Here is what happens when I run git push heroku master

-----> Python app detected
-----> Preparing Python runtime (python-3.4.0)
-----> Installing Setuptools (2.1)
-----> Installing Pip (1.5.4)
-----> Installing dependencies using Pip (1.5.4)
Exception:
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.4/site-packages/pip-1.5.4-py3.4.egg/pip/basecommand.py", line 122, in main
      status = self.run(options, args)
  File "/app/.heroku/python/lib/python3.4/site-packages/pip-1.5.4-py3.4.egg/pip/commands/install.py", line 262, in run
      for req in parse_requirements(filename, finder=finder, options=options, session=session):
  File "/app/.heroku/python/lib/python3.4/site-packages/pip-1.5.4-py3.4.egg/pip/req.py", line 1546, in parse_requirements
      session=session,
  File "/app/.heroku/python/lib/python3.4/site-packages/pip-1.5.4-py3.4.egg/pip/download.py", line 275, in get_file_content
      content = f.read()
  File "/app/.heroku/python/lib/python3.4/codecs.py", line 313, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)
   UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

       Storing debug log for failure in /app/.pip/pip.log

 !     Push rejected, failed to compile Python app

Here the content of my requirements.txt file (created with pip freeze > requirements.txt)

Django==1.6.2
dj-database-url==0.3.0
dj-static==0.0.5
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.2
pystache==0.5.3
static==1.0.2

Here my Procfile (btw: gunicorn seems to be a Unix "only" command and does not work for Windows; read here):

web: gunicorn mytodo.wsgi

The Heroku tutorial does not mention a setup.py file, but it seems that one is necessary, so I simply copied a template.... not my preferred solution, but I did not know what else to do.

setup(
    name='mysite',
    version='0.1.0',
    install_requires=[],  # Don't put anything here, just use requirements.txt
    packages=['mysite'],
    package_dir={'mysite': 'src/mysite'},
)

What could be going on: - The unicode error message could stem from the Procfile. Somewhere online I read that it has to be ASCII file, but I am not sure how to declare that as the Procfile has no file ending. - The setup.py file is wrong.

Any help is appreciated. Thanks!

like image 565
raummensch Avatar asked Apr 20 '14 22:04

raummensch


1 Answers

I encountered this exact problem during my own attempt to deploy a Django app to Heroku on Windows 7. The cause turned out to be this: The command pip freeze >requirements.txt encodes the file in UTF-16 format. Heroku expects requirements.txt to be ansi-encoded.

To fix it, I opened requirements.txt in Notepad, went to File->Save As, and set the Encoding to ANSI before saving again. After git-committing the new requirements.txt, I was able to run git push heroku master and it worked as expected.

like image 131
Nolan Avatar answered Sep 22 '22 15:09

Nolan