【问题标题】:Push project to Heroku has been rejected if I change Python version如果我更改 Python 版本,将项目推送到 Heroku 已被拒绝
【发布时间】:2020-02-21 17:23:00
【问题描述】:

我有一个使用 Python 2 在 heroku 上的 Python Scrapy 项目。如果我有一些代码更新,我仍然可以推送到 Heroku。

现在我想将 python 版本更新到 Python 3。

看起来 Heroku 支持 Python 3: https://devcenter.heroku.com/changelog-items/1442

所以我将我的runtime.txt 文件从python-2.7.15 更新为python-3.7.0

而我的requirements.txt 是:

pymongo==3.5.1
Scrapy==1.4.0
scrapyd==1.0.1
scrapy-heroku==0.7.1
cffi==1.6.0
requests==2.5.3

然后输入git push heroku master,这里是终端的信息:

Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 16 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 740 bytes | 740.00 KiB/s, done.
Total 9 (delta 6), reused 1 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote:  !     Python has released a security update! Please consider upgrading to python-3.7.6
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Found python-2.7.15, removing
remote: -----> Installing python-3.7.0
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote:        Collecting pymongo==3.5.1
remote:          Downloading pymongo-3.5.1.tar.gz (1.3 MB)
remote:        Collecting Scrapy==1.4.0
remote:          Downloading Scrapy-1.4.0-py2.py3-none-any.whl (248 kB)
remote:        Collecting scrapyd==1.0.1
remote:          Downloading scrapyd-1.0.1.tar.gz (32 kB)
remote:        Collecting scrapy-heroku==0.7.1
remote:          Downloading scrapy-heroku-0.7.1.tar.gz (5.2 kB)
remote:        Collecting cffi==1.6.0
remote:          Downloading cffi-1.6.0.tar.gz (397 kB)
remote:        Collecting requests==2.5.3
remote:          Downloading requests-2.5.3-py2.py3-none-any.whl (468 kB)
remote:        Collecting Twisted>=13.1.0
remote:          Downloading Twisted-19.10.0-cp37-cp37m-manylinux1_x86_64.whl (3.1 MB)
remote:        Collecting cssselect>=0.9
remote:          Downloading cssselect-1.1.0-py2.py3-none-any.whl (16 kB)
remote:        Collecting parsel>=1.1
remote:          Downloading parsel-1.5.2-py2.py3-none-any.whl (12 kB)
remote:        Collecting w3lib>=1.17.0
remote:          Downloading w3lib-1.21.0-py2.py3-none-any.whl (20 kB)
remote:        Collecting pyOpenSSL
remote:          Downloading pyOpenSSL-19.1.0-py2.py3-none-any.whl (53 kB)
remote:        Collecting service-identity
remote:          Downloading service_identity-18.1.0-py2.py3-none-any.whl (11 kB)
remote:        Collecting PyDispatcher>=2.0.5
remote:          Downloading PyDispatcher-2.0.5.tar.gz (34 kB)
remote:        Collecting lxml
remote:          Downloading lxml-4.5.0-cp37-cp37m-manylinux1_x86_64.whl (5.7 MB)
remote:        Collecting six>=1.5.2
remote:          Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
remote:        Collecting queuelib
remote:          Downloading queuelib-1.5.0-py2.py3-none-any.whl (13 kB)
remote:        Collecting distribute
remote:          Downloading distribute-0.7.3.zip (145 kB)
remote:            ERROR: Command errored out with exit status 1:
remote:             command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bb2wfsg5/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bb2wfsg5/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-bb2wfsg5/distribute/pip-egg-info
remote:                 cwd: /tmp/pip-install-bb2wfsg5/distribute/
remote:            Complete output (15 lines):
remote:            Traceback (most recent call last):
remote:              File "<string>", line 1, in <module>
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/setuptools/__init__.py", line 2, in <module>
remote:                from setuptools.extension import Extension, Library
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/setuptools/extension.py", line 5, in <module>
remote:                from setuptools.dist import _get_unpatched
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/setuptools/dist.py", line 7, in <module>
remote:                from setuptools.command.install import install
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/setuptools/command/__init__.py", line 8, in <module>
remote:                from setuptools.command import install_scripts
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/setuptools/command/install_scripts.py", line 3, in <module>
remote:                from pkg_resources import Distribution, PathMetadata, ensure_directory
remote:              File "/tmp/pip-install-bb2wfsg5/distribute/pkg_resources.py", line 1518, in <module>
remote:                register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
remote:            AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
remote:            ----------------------------------------
remote:        ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to myproject.
remote: 
To https://git.heroku.com/myproject.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/myproject.git'

如果我的项目 python 的版本仍然是 2.7.15,push 可以工作。

我不知道为什么我将它更改为 3.7.0 时会被拒绝,我如何在 Heroku 上将我的项目更新到 Python 3?

当更改requests==2.23.0

输出是:

Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 16 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (19/19), 1.59 KiB | 812.00 KiB/s, done.
Total 19 (delta 14), reused 1 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote:  !     Python has released a security update! Please consider upgrading to python-3.7.6
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Found python-2.7.15, removing
remote: -----> Installing python-3.7.0
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote:        Collecting pymongo==3.5.1
remote:          Downloading pymongo-3.5.1.tar.gz (1.3 MB)
remote:        Collecting Scrapy==1.4.0
remote:          Downloading Scrapy-1.4.0-py2.py3-none-any.whl (248 kB)
remote:        Collecting scrapyd==1.0.1
remote:          Downloading scrapyd-1.0.1.tar.gz (32 kB)
remote:        Collecting scrapy-heroku==0.7.1
remote:          Downloading scrapy-heroku-0.7.1.tar.gz (5.2 kB)
remote:        Collecting cffi==1.6.0
remote:          Downloading cffi-1.6.0.tar.gz (397 kB)
remote:        Collecting requests==2.23.0
remote:          Downloading requests-2.23.0-py2.py3-none-any.whl (58 kB)
remote:        Collecting queuelib
remote:          Downloading queuelib-1.5.0-py2.py3-none-any.whl (13 kB)
remote:        Collecting cssselect>=0.9
remote:          Downloading cssselect-1.1.0-py2.py3-none-any.whl (16 kB)
remote:        Collecting service-identity
remote:          Downloading service_identity-18.1.0-py2.py3-none-any.whl (11 kB)
remote:        Collecting w3lib>=1.17.0
remote:          Downloading w3lib-1.21.0-py2.py3-none-any.whl (20 kB)
remote:        Collecting six>=1.5.2
remote:          Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
remote:        Collecting pyOpenSSL
remote:          Downloading pyOpenSSL-19.1.0-py2.py3-none-any.whl (53 kB)
remote:        Collecting parsel>=1.1
remote:          Downloading parsel-1.5.2-py2.py3-none-any.whl (12 kB)
remote:        Collecting Twisted>=13.1.0
remote:          Downloading Twisted-19.10.0-cp37-cp37m-manylinux1_x86_64.whl (3.1 MB)
remote:        Collecting lxml
remote:          Downloading lxml-4.5.0-cp37-cp37m-manylinux1_x86_64.whl (5.7 MB)
remote:        Collecting PyDispatcher>=2.0.5
remote:          Downloading PyDispatcher-2.0.5.tar.gz (34 kB)
remote:        Collecting distribute
remote:          Downloading distribute-0.7.3.zip (145 kB)
remote:            ERROR: Command errored out with exit status 1:
remote:             command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-60s4l_1v/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-install-60s4l_1v/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-60s4l_1v/distribute/pip-egg-info
remote:                 cwd: /tmp/pip-install-60s4l_1v/distribute/
remote:            Complete output (15 lines):
remote:            Traceback (most recent call last):
remote:              File "<string>", line 1, in <module>
remote:              File "/tmp/pip-install-60s4l_1v/distribute/setuptools/__init__.py", line 2, in <module>
remote:                from setuptools.extension import Extension, Library
remote:              File "/tmp/pip-install-60s4l_1v/distribute/setuptools/extension.py", line 5, in <module>
remote:                from setuptools.dist import _get_unpatched
remote:              File "/tmp/pip-install-60s4l_1v/distribute/setuptools/dist.py", line 7, in <module>
remote:                from setuptools.command.install import install
remote:              File "/tmp/pip-install-60s4l_1v/distribute/setuptools/command/__init__.py", line 8, in <module>
remote:                from setuptools.command import install_scripts
remote:              File "/tmp/pip-install-60s4l_1v/distribute/setuptools/command/install_scripts.py", line 3, in <module>
remote:                from pkg_resources import Distribution, PathMetadata, ensure_directory
remote:              File "/tmp/pip-install-60s4l_1v/distribute/pkg_resources.py", line 1518, in <module>
remote:                register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
remote:            AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
remote:            ----------------------------------------
remote:        ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to myproject.
remote: 
To https://git.heroku.com/myproject.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/myproject.git'

【问题讨论】:

  • ...other info 是什么?这就是有用的信息所在。
  • 是的,你的权利,我已经拍了所有的信息,请看一下。
  • 对不起,我尝试purging your build cache 不工作。我尝试使用installing pipdeptree 并深入了解其中的情况。我最近会报告的。

标签: python heroku scrapy


【解决方案1】:

你(间接地)依赖distribute,这是一个

旧包 [提供] 安装 Setuptools 0.7+ 的简单兼容层

由于

,它没有正确构建
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

这是有道理的,因为importlib._bootstrap 在 Python 3.7 中不包含 SourceFileLoader 类。

distribute 的 PyPI 页面显示它与 Python 2.4、2.5、2.6、2.7、3.1、3.2 和 3.3 兼容。

它正在被an old version of requests 拉入。更新您的 requirements.txt 以使用更新的版本:the latest is currently 2.23.0

尝试从requirements.txt 安装在干净的本地虚拟环境中始终是一个好主意,以确保在重大升级后拥有良好的配置,并且从 Python 2.7 升级到 Python 3.7 绝对算作重大升级。

一旦您对 requirements.txt 的内容有信心,请提交并重新部署。

【讨论】:

  • 感谢您的帮助,所以我已将我的请求从 requests==2.5.3 降级为 requests==2.23.0 ?我重新部署项目仍然从 Heroku 获得 AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'。任何想法 ?谢谢。
  • 这是一个重大的升级,而不是降级。 requests 2.5.3 五年前问世。请在您的问题中编辑新的构建输出。
  • 再次感谢,我在设置requests==2.23.0时更新了新输出
  • 抱歉,我今天早上查看手机时错过了这一点。您可能有一个太旧的缓存依赖项。试试purging your build cache。如果那不这样做,我们将不得不更深入地挖掘。尝试安装pipdeptree 并在本地使用它来查找依赖于distribute 的任何内容。消除或升级你发现的任何东西,这取决于它是什么。
  • 谢谢。我会尝试你的建议,看看下一步会发生什么。
猜你喜欢
  • 2013-02-08
  • 1970-01-01
  • 2017-01-09
  • 2021-09-22
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2021-05-06
相关资源
最近更新 更多