سؤال

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!

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

Try removing static==1.0.2 from requirements.txt. It doesn't play nice with python 3.4. However, it will be installed properly through dj-static. This worked for me:

Django==1.5.1
dj-database-url==0.2.2
dj-static==0.0.5
gunicorn==18.0
psycopg2==2.5.1

I'm no expert, but take a look at this blog post about deploying to Heroku from a Windows machine. Hope it helps. http://www.swarley.me.uk/blog/2014/02/24/create-a-django-development-environment-on-64-bit-windows-for-heroku-deployment/

update: ok, I think I have a better answer. First, Heroku flat out says Windows users will have problems that Linux and iOS users will not: https://devcenter.heroku.com/articles/bundler-windows-gemfile The article is about Ruby but the same problems will apply to other languages because they are talking about the OS you are coming from.

However, this solution worked for me: Use Bitbucket as your remote repository, and upload to it from your Windows machine. Then from Bitbucket upload to Heroku. Here is a very similar question and answer here on SO: Deploying to Heroku using git on bitbucket

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top