簡體   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