rau*_*sch 5 python django pip heroku
我正在尝试使用Django/Heroku入门教程部署我的第一个使用Django/Heroku的示例应用程序.
我的工具:Python 3.4和Windows 7 PowerShell.
我的挑战:部署到Heroku失败了,我不知道为什么.在我第一次"git push"时,我看到默认情况下使用了python-2.7.0.然后我runtime.txt在app根目录中添加了一个(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
Run Code Online (Sandbox Code Playgroud)
这里是我的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
Run Code Online (Sandbox Code Playgroud)
在这里我的Procfile(顺便说一句:gunicorn似乎是一个Unix"唯一"命令,不适用于Windows; 请在这里阅读):
web: gunicorn mytodo.wsgi
Run Code Online (Sandbox Code Playgroud)
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'},
)
Run Code Online (Sandbox Code Playgroud)
可能会发生什么: - unicode错误消息可能源于Procfile.我在网上看到它必须是ASCII文件,但我不知道如何声明,因为Procfile没有文件结尾. - setup.py文件错误.
任何帮助表示赞赏.谢谢!
小智 4
我在尝试将 Django 应用程序部署到 Windows 7 上的 Heroku 时遇到了这个确切的问题。原因如下:该命令pip freeze >requirements.txt以 UTF-16 格式对文件进行编码。Heroku 希望requirements.txt 采用ansi 编码。
为了解决这个问题,我在记事本中打开requirements.txt,转到文件->另存为,然后将编码设置为ANSI,然后再次保存。git 提交新的requirements.txt 后,我能够运行git push heroku master并且它按预期工作。