加入收藏 | 设为首页 | 会员中心 | 我要投稿 阜阳站长网 (https://www.0558zz.com/)- 科技、建站、内容创作、云计算、网络安全!
当前位置: 首页 > 编程开发 > Python > 正文

将Django / Python 3.4部署到Heroku

发布时间:2020-08-01 18:36:08 所属栏目:Python 来源:互联网
导读:我正在尝试使用Django / Heroku入门教程部署我的第一个使用Django / Heroku的示例应用程序.我的工具:Python 3.4和Windows 7 PowerShell.我的挑战:部署到Heroku失败了,我不知道为什么.在我第一次“git push”时,我看到默认情况下使用了python-2.7.0.然后我在

我正在尝试使用Django / Heroku入门教程部署我的第一个使用Django / Heroku的示例应用程序.

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

我的挑战:部署到Heroku失败了,我不知道为什么.在我第一次“git push”时,我看到默认情况下使用了python-2.7.0.然后我在app根目录中添加了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(btw:gunicorn似乎是一个Unix“唯一”命令,不适用于Windows; read here):

web: gunicorn mytodo.wsgi

Heroku教程没有提到setup.py文件,but it seems that one is necessary,所以我只是复制了一个模板….不是我喜欢的解决方案,但我不知道还能做什么.

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

可能会发生什么:
– unicode错误消息可能来自Procfile.我在网上看到它必须是ASCII文件,但我不知道如何声明,因为Procfile没有文件结尾.
– setup.py文件错误.

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

最佳答案 在我自己尝试在Windows 7上将Django应用程序部署到Heroku时遇到了这个问题.原因是:命令pip freeze> requirements.txt以UTF-16格式对文件进行编码. Heroku期望requirements.txt被ansi编码.

为了解决这个问题,我在记事本中打开了requirements.txt,转到了File->另存为,并在再次保存之前将编码设置为ANSI.在git-commit新的requirements.txt之后,我能够运行git push heroku master并且它按预期工作.

(编辑:阜阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读