Flynn: 未安装自定义 git pip 包

创建于 2018-04-09  ·  9评论  ·  资料来源: flynn/flynn

我的 Pipfile 中有一个依赖项,它安装得很好,来自 git(开源存储库)。 当我等待合并并发布到 PyPy 时,它是一个库的修补版本:

requests-respectful = { git = '[email protected]:mcescalante/requests-respectful.git', editable = 'true' }

当我部署到 flynn 时,一切都成功部署和发布(Pipfile.lock 安装没有错误,Pipfile.lock 已更新),但是当我导航到我的应用程序时,我遇到了错误:

No module named 'requests_respectful'

我通过运行flynn run bash然后pip list进一步检查。 返回的列表中缺少该软件包,表明它未安装。

我快速查看了用于 Python 的上游 Heroku buildpack 中的问题,以查看是否存在未解决的问题,但此部署实际上适用于 Heroku 本身,并且上游没有明显的重大问题会导致此问题。 您可以在 repo 中找到我正在使用的 Pipfile: https :

所有9条评论

@mcescalante我怀疑安装失败,因为您使用的是 SSH URI,但 Flynn 不信任 GitHub 主机密钥。

我建议使用 HTTP URI:

https://github.com/mcescalante/requests-respectful.git

或更新gitreceive应用程序,使其信任 GitHub SSH 主机密钥:

flynn -a gitreceive env set SSH_CLIENT_HOSTS="$(ssh-keyscan -H github.com)"

@lmars感谢您的回复! 我在另一个问题线程中看到了你的gitreceive命令,并且在打开这个问题之前已经添加了我自己的密钥 - 添加我自己的密钥解决了 Pipfile.lock 安装过程中关于无法克隆 repo 的先前错误。

我会试一试这两种方法,看看会发生什么,然后回来报告!

刚刚进行了两项更改,并且在我的应用程序中看到了完全相同的错误,但在部署时没有问题。 这是我的部署日志,没有显示安装错误:

➜  oh-fitbit-integration git:(fix-flynn) git push flynn fix-flynn:master                     
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 557 bytes | 557.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0)
-----> Building fitbit...
-----> Python app detected
-----> Installing pip
-----> Installing requirements with latest pipenv...
       Installing dependencies from Pipfile.lock (82d7ab)…
-----> $ python manage.py collectstatic --noinput
       /app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
       """)
       DEBUG 2018-04-09 19:58:42,724 base 822 xxxx Configuring Raven for host: None
       INFO 2018-04-09 19:58:42,725 base 822 xxxx Raven is not configured (logging is disabled). Please see the documentation for more information.
       120 static files copied to '/tmp/build/app/staticfiles', 134 post-processed.

-----> Discovering process types
       Procfile declares types -> release, web, worker
-----> Compiled slug size is 67.38 MiB
-----> Creating release...
=====> Application deployed
To https://myclusterurlhere-redacted/fitbit.git
   da75e82..f32f030  fix-flynn -> master

flynn run bashpip list输出:

➜  oh-fitbit-integration git:(fix-flynn) flynn run bash
flynn@hash-redaced:~$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
amqp (2.2.2)
arrow (0.12.1)
billiard (3.5.0.3)
celery (4.1.0)
certifi (2018.1.18)
chardet (3.0.4)
defusedxml (0.5.0)
dj-database-url (0.5.0)
Django (2.0.4)
gunicorn (19.7.1)
idna (2.6)
kombu (4.1.0)
multidict (4.1.0)
oauthlib (2.0.7)
pip (9.0.3)
pipenv (11.9.0)
psycopg2 (2.7.4)
PyJWT (1.6.1)
python-dateutil (2.7.2)
python-social-auth (0.3.6)
python3-openid (3.1.0)
pytz (2018.3)
PyYAML (3.12)
raven (6.6.0)
redis (2.10.6)
requests (2.18.4)
requests-oauthlib (0.8.0)
setuptools (39.0.1)
six (1.11.0)
social-auth-core (1.7.0)
urllib3 (1.22)
vcrpy (1.11.1)
vine (1.1.4)
virtualenv (15.2.0)
virtualenv-clone (0.3.0)
wheel (0.31.0)
whitenoise (3.3.1)
wrapt (1.10.11)
yarl (1.1.1)

这是#3932 的副本。 我相信这是由于在 python buildpack 中做出的一些关于路径的假设导致egg-link文件中的路径无效/不正确。

还有这个最近关闭的问题: https :

尝试使用最新的 buildpack:

flynn env set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python#v132

@titanous啊,是的,这听起来是正确的。 这个问题正好被我忽略了,我想是因为我在打开这个 😄 之前在我的问题搜索中寻找错误的词。

@lmars好主意,我只是No module named 'requests_respectful' ,我的 buildpack 在 env 中设置为BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python#v132

好吧,由于我一直在解决这个问题(认为这是新的 pipenv 问题),为了完整起见,我想添加 Flynn 与 Heroku 的比较。 (在我的情况下,使用 luminol 包作为 Pipenv 文件中的可编辑依赖项)

弗林:

flynn<strong i="7">@x</strong>:~$ python
Python 3.6.6 (default, Aug  1 2018, 21:10:48) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/app', '/app/.heroku/python/lib/python36.zip', '/app/.heroku/python/lib/python3.6', '/app/.heroku/python/lib/python3.6/lib-dynload', '/app/.heroku/python/lib/python3.6/site-packages']

flynn<strong i="8">@x</strong>:~$ cat /app/.heroku/python/lib/python3.6/site-packages/easy-install.pth
/tmp/build//app/src/luminol/src

赫鲁克:

~ $ python
Python 3.6.6 (default, Aug  1 2018, 21:10:15) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/app', '/app/.heroku/python/lib/python36.zip', '/app/.heroku/python/lib/python3.6', '/app/.heroku/python/lib/python3.6/lib-dynload', '/app/.heroku/python/lib/python3.6/site-packages', '/app/src/luminol/src']


~ $ cat /app/.heroku/python/lib/python3.6/site-packages/easy-install.pth
/app/src/luminol/src

TLDR;

将下面的脚本存储到/bin/post_compile 文件夹:

#!/usr/bin/env bash

set +e
find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 2> /dev/null | xargs -r -0 -n 1 sed -i -e "s#[^>]*/app/#$(pwd)/#" &> /dev/null
set -e

解释:

Python buildpack (https://github.com/heroku/heroku-buildpack-python/blob/v144/bin/compile)

按以下顺序执行此特定步骤:

#L178:源“$BIN_DIR/steps/hooks/pre_compile”
#L201:源“$BIN_DIR/steps/pipenv-python-version”
#L256:源“$BIN_DIR/steps/eggpath-fix”
#L295:源“$BIN_DIR/steps/pip-install”
#L359:源“$BIN_DIR/steps/hooks/post_compile”
#L363:源“$BIN_DIR/steps/eggpath-fix2

这里有趣的部分在/eggpath-fix/eggpath-fix2

/eggpath-fix
它替换(通过 sed) s#/app/#/$(pwd)/# /app/ ~> /$(pwd)/

/eggpath-fix2
它替换(通过 sed) s#$(pwd)#/app# $(pwd) ~> /app

出于某种原因,Heroku 在这种状态下以eggpath-fix2结束:
$(pwd) 计算为/tmp/build_HASH
/tmp/build_HASH/src/luminol/src ~> /app/src/luminol/src

但弗林在状态eggpath-fix2之后结束:
$(pwd) 计算为/tmp/build/app
/tmp/build//tmp/build/app/src/luminol/src ~> /tmp/build//app/src/luminol/src

您可以在之前的评论中看到。
不知道哪里出错了(替换变得疯狂)但建议的修复(作为 post_compile 脚本运行,它几乎发生在eggpath-fix2 )并且应该使用 sed 在 flynn 的 python buildpack 执行期间更正任何错误的设置路径:

s#[^>]*/app/#$(pwd)/#
[^>]*(非贪婪匹配) - 由http://0x2a.at/blog/2008/07/sed--non-greedy-matching/ 提供

所以这应该解决/tmp/build//tmp/build/app/src/luminol/src ~> /tmp/build/app/src/luminol/src
它最终会被eggpath-fix2压缩成/app/src/luminol/src从而产生正确的 python 路径。

TLDR 的扩展版本;

#!/usr/bin/env bash

DEBUG=true

if [ "$DEBUG" = true ] ; then
    echo "PWD : $(pwd)"
    echo "Looking for .pth packages"
    find .heroku/python/lib/python*/site-packages/ -name "*.pth"
    echo "------- Original content(s) -------"
    find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 2> /dev/null | xargs -r -0 -n 1 cat
fi

set +e
# http://0x2a.at/blog/2008/07/sed--non-greedy-matching/
find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 2> /dev/null | xargs -r -0 -n 1 sed -i -e "s#[^>]*/app/#$(pwd)/#" &> /dev/null
set -e

if [ "$DEBUG" = true ] ; then
    echo "------- Replaced content(s) -------"
    find .heroku/python/lib/python*/site-packages/ -name "*.pth" -print0 2> /dev/null | xargs -r -0 -n 1 cat
fi

Flynn 无人维护,我们的基础设施将于 2021 年 6 月 1 日关闭。有关详细信息,请参阅自述文件

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

kipparker picture kipparker  ·  3评论

titanous picture titanous  ·  4评论

hadifarnoud picture hadifarnoud  ·  3评论

tuukkamustonen picture tuukkamustonen  ·  5评论

lmars picture lmars  ·  4评论