繁体   English   中英

将Django / Python 3.4部署到Heroku

[英]Deploying Django/Python 3.4 to Heroku

我正在尝试使用Django / Heroku入门教程将第一个示例应用程序与Django / Heroku一起部署。

我的工具:Python 3.4和Windows 7 PowerShell。

我的挑战:部署到Heroku失败了,我不确定为什么。 第一次执行“ git push”时,我看到默认情况下使用的是python-2.7.0。 然后,我在应用程序根目录中添加了runtime.txt (python-3.4.0)文件。

这是我运行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

这是我的requirements.txt文件的内容(通过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

这是我的Procfile (顺便说一句:gunicorn似乎是Unix上的“仅”命令,不适用于Windows;请参阅此处 ):

web: gunicorn mytodo.wsgi

Heroku教程没有提到setup.py文件, 但是似乎一个文件是必需的 ,因此我只是复制了一个模板。。。。

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'},
)

可能发生的情况: Procfile错误消息可能源自Procfile 在网上某个地方,我读到它必须是ASCII文件,但是由于Procfile没有文件结尾,因此我不确定如何声明它。 -setup.py文件错误。

任何帮助表示赞赏。 谢谢!

在我自己尝试将Django应用程序部署到Windows 7上的Heroku时,遇到了这个确切的问题。原因是:命令pip freeze >requirements.txt将文件编码为UTF-16格式。 Heroku要求require.txt是经过ansi编码的。

要解决此问题,我在记事本中打开了requirements.txt文件,转到“文件”->“另存为”,然后将编码设置为ANSI,然后再次保存。 在git提交新的requirements.txt之后,我能够运行git push heroku master ,并且按预期工作。

尝试从requirements.txt中删除static == 1.0.2。 它在python 3.4中不能很好地工作。 但是,它将通过dj-static正确安装。 这为我工作:

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

我不是专家,但是请看一下有关从Windows机器部署到Heroku的博客文章。 希望能帮助到你。 http://www.swarley.me.uk/blog/2014/02/24/create-a-django-development-environment-on-64-bit-windows-for-heroku-deployment/

更新:好的,我想我有一个更好的答案。 首先,Heroku坦率地说Windows用户将遇到Linux和iOS用户不会遇到的问题: https : //devcenter.heroku.com/articles/bundler-windows-gemfile本文是关于Ruby的,但同样的问题也适用于其他语言因为他们在谈论您来自的操作系统。

但是,该解决方案对我有用:将Bitbucket用作您的远程存储库,然后从Windows计算机上上传到它。 然后从Bitbucket上传到Heroku。 这是关于SO的非常相似的问答: 在bitbucket上使用git部署到Heroku

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM