【问题标题】:Heroku push rejected due to pip/distribute bug. What's the workaround?由于 pip/distribute 错误,Heroku 推送被拒绝。解决方法是什么?
【发布时间】:2013-06-05 03:33:24
【问题描述】:

我的本​​地 git/virtualenv 使用的是 pip 版本 1.3.1。当我尝试将我的 Python 3.3.2 应用程序推送到 Heroku 时,我得到了

Downloading/unpacking distribute==0.6.34 (from -r requirements.txt (line 5))
     Running setup.py egg_info for package distribute
       Traceback (most recent call last):
         File "<string>", line 3, in <module>
         File "./setuptools/__init__.py", line 2, in <module>
           from setuptools.extension import Extension, Library
         File "./setuptools/extension.py", line 5, in <module>
           from setuptools.dist import _get_unpatched
         File "./setuptools/dist.py", line 103
           except ValueError, e:
                            ^
       SyntaxError: invalid syntax
       Complete output from command python setup.py egg_info:
       Traceback (most recent call last):

     File "<string>", line 3, in <module>

     File "./setuptools/__init__.py", line 2, in <module>

       from setuptools.extension import Extension, Library

     File "./setuptools/extension.py", line 5, in <module>

       from setuptools.dist import _get_unpatched

     File "./setuptools/dist.py", line 103

       except ValueError, e:

                        ^

   SyntaxError: invalid syntax

   ----------------------------------------
   Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-u58345/distribute
   Storing complete log in /app/.pip/pip.log

 !     Push rejected, failed to compile Python app

鉴于我无法在 Heroku 的服务器上手动安装 distribute,我应该如何避免这个错误?

【问题讨论】:

    标签: python heroku pip python-3.3 distribute


    【解决方案1】:

    您看到的行为是 pip 本身的问题: https://github.com/pypa/pip/issues/650

    好像pip使用distribute来升级distribute。

    但是,您需要做的是从 requirements.txt 中完全删除分发来修复您的错误。它已经存在,因为它是由 buildpack 安装的,无需使用 pip 再次安装。

    我相信您实际上可以并且正在通过默认的 buildpack 在 heroku 的服务器上安装分发包。 Heroku 的 Python 支持以 buildpack 的形式实现。您可以阅读有关 buildpack 的更多信息here

    如果您希望拥有特定版本的分发,在这种情况下是没有 pip-bug 的版本,您必须在您的应用正在使用的 buildpack 中替换它的源代码。可以这样做:

    1. https://github.com/heroku/heroku-buildpack-python 的 heroku 获取原始 buildpack
    2. 在您克隆的 buildpack(在撰写本文时)中,您将找到 /vendor/distribute-0.6.36。这就是问题。将其替换为a newer version of distribute
    3. 在 buildpack 的 bin/compile 脚​​本中,替换 buildpack 正在使用的分发版本。就我而言,这是replacing line 31 DISTRIBUTE_VERSION="0.6.36"DISTRIBUTE_VERSION="0.6.45"

    4. 将你的 buildpack 上传到 github 并告诉 heroku 使用它

    $ heroku config:set BUILDPACK_URL=https://github.com/you/name-of-buildpack-python-repo.git

    交替

    告诉 heroku 使用我的自定义 buildpack 而不是原来的。我的 builbpack 与原始版本的唯一区别是步骤 1-4 中描述的那些。

    要覆盖现有应用程序的 buildpack:

    $ heroku config:set BUILDPACK_URL=https://github.com/jhnwsk/heroku-buildpack-python.git

    或者如果你正在创建一个新的应用程序

    $ heroku create myapp --buildpack https://github.com/jhnwsk/heroku-buildpack-python.git

    当您在进行这些更改后将应用程序推送到 Heroku 时,您应该会看到类似

    -----> Fetching custom git buildpack... done
    -----> Python app detected
    -----> No runtime.txt provided; assuming python-2.7.4.
    -----> Preparing Python runtime (python-2.7.4)
    -----> Installing Distribute (0.6.45)
    -----> Installing Pip (1.3.1)
    

    这意味着您正在运行您的自定义分发版本。

    【讨论】:

    • 如果您不介意,您愿意详细介绍这四个步骤吗?这些对我这个新人来说绝对没有任何意义。
    • 当然可以。我编辑了我的答案以更详细,尽管我不知道这是否使它变得更糟或更好。如果你告诉我哪些部分不清楚,我们可以找出更有意义的东西:)
    猜你喜欢
    • 1970-01-01
    • 2017-01-09
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多