[英]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. 我正在尝试使用Django / Heroku入门教程将第一个示例应用程序与Django / Heroku一起部署。
My tools: Python 3.4 and Windows 7 PowerShell. 我的工具:Python 3.4和Windows 7 PowerShell。
My challenge: deploying to Heroku fails and I am not sure why. 我的挑战:部署到Heroku失败了,我不确定为什么。 Upon my first "git push" I saw that python-2.7.0 was used by default.
第一次执行“ git push”时,我看到默认情况下使用的是python-2.7.0。 I then added a
runtime.txt
(python-3.4.0) file in the app root. 然后,我在应用程序根目录中添加了
runtime.txt
(python-3.4.0)文件。
Here is what happens when I run git push heroku master
这是我运行
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
) 这是我的
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
Here my Procfile
(btw: gunicorn seems to be a Unix "only" command and does not work for Windows; read here ): 这是我的
Procfile
(顺便说一句:gunicorn似乎是Unix上的“仅”命令,不适用于Windows;请参阅此处 ):
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. 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'},
)
What could be going on: - The unicode error message could stem from the Procfile
. 可能发生的情况:
Procfile
错误消息可能源自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. 在网上某个地方,我读到它必须是ASCII文件,但是由于Procfile没有文件结尾,因此我不确定如何声明它。 - The setup.py file is wrong.
-setup.py文件错误。
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. 在我自己尝试将Django应用程序部署到Windows 7上的Heroku时,遇到了这个确切的问题。原因是:命令
pip freeze >requirements.txt
将文件编码为UTF-16格式。 Heroku expects requirements.txt to be ansi-encoded. Heroku要求require.txt是经过ansi编码的。
To fix it, I opened requirements.txt in Notepad, went to File->Save As, and set the Encoding to ANSI before saving again. 要解决此问题,我在记事本中打开了requirements.txt文件,转到“文件”->“另存为”,然后将编码设置为ANSI,然后再次保存。 After git-committing the new requirements.txt, I was able to run
git push heroku master
and it worked as expected. 在git提交新的requirements.txt之后,我能够运行
git push heroku master
,并且按预期工作。
Try removing static==1.0.2 from requirements.txt. 尝试从requirements.txt中删除static == 1.0.2。 It doesn't play nice with python 3.4.
它在python 3.4中不能很好地工作。 However, it will be installed properly through dj-static.
但是,它将通过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. 我不是专家,但是请看一下有关从Windows机器部署到Heroku的博客文章。 Hope it helps.
希望能帮助到你。 http://www.swarley.me.uk/blog/2014/02/24/create-a-django-development-environment-on-64-bit-windows-for-heroku-deployment/
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.
首先,Heroku坦率地说Windows用户将遇到Linux和iOS用户不会遇到的问题: https : //devcenter.heroku.com/articles/bundler-windows-gemfile本文是关于Ruby的,但同样的问题也适用于其他语言因为他们在谈论您来自的操作系统。
However, this solution worked for me: Use Bitbucket as your remote repository, and upload to it from your Windows machine. 但是,该解决方案对我有用:将Bitbucket用作您的远程存储库,然后从Windows计算机上上传到它。 Then from Bitbucket upload to Heroku.
然后从Bitbucket上传到Heroku。 Here is a very similar question and answer here on SO: Deploying to Heroku using git on bitbucket
这是关于SO的非常相似的问答: 在bitbucket上使用git部署到Heroku
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.