python - 由于 pip/distribute 错误,Heroku 推送被拒绝。解决方法是什么?

标签 python heroku pip python-3.3 distribute

我的本​​地 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,我应该如何避免这个错误?

最佳答案

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

好像pip是用distribute升级distribute的

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

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

如果您希望拥有特定版本的分发,在本例中是没有 pip-bug 的版本,您必须在您的应用程序使用的构建包中替换它的源代码。可以这样做:

  1. https://github.com/heroku/heroku-buildpack-python 从 heroku 获取原始构建包
  2. 在您克隆的构建包中(在撰写本文时),您将找到 /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. 将您的构建包上传到 github 并告诉 heroku 使用它

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

或者

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

覆盖现有应用程序的构建包:

$ 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)

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

关于python - 由于 pip/distribute 错误,Heroku 推送被拒绝。解决方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16931105/

相关文章:

javascript - Heroku 环境导致 Java/Nashorn/ReactJS 应用程序崩溃

python - 安装python包时出现"There was a problem confirming the ssl certificate"

python - 下载了Python版的SciPy,无法使用

python - 选择具有给定属性值的网络节点

ruby-on-rails - Gmail SMTP:Net::SMTPAuthenticationError(需要 530-5.5.1 身份验证。了解更多信息,请访问

Python:无法迭代模拟对象中的模拟数据库值

node.js - Heroku、Node、Express、SSL 的 ERR_SSL_PROTOCOL_ERROR

python - 安装 python-docx 时出错

python - 如何在python中测试数据库连通性?

python - 在 macOS 上的 VS Code 中启动 Python 脚本时出现 `SyntaxError: invalid syntax`