Google 应用程序引擎部署失败 - 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”)

2023-12-21

我们正在使用命令提示符c:\gcloud app deploy app.yaml,但出现以下错误:

Running "python3 -m pip install --requirement requirements.txt --upgrade --upgrade-strategy only-if-needed --no-warn-script-location --no-warn-conflicts --force-reinstall --no-compile (PIP_CACHE_DIR=/layers/google.python.pip/pipcache PIP_DISABLE_PIP_VERSION_CHECK=1)"
Step #2 - "build": /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": Done "python3 -m pip install --requirement requirements.txt --upgr..." (34.49892ms)
Step #2 - "build": Failure: (ID: 0ea8a540) /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Step #2 - "build": Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (12.758866ms)
Step #2 - "build": ERROR: failed to build: exit status 1
Finished Step #2 - "build"
ERROR
ERROR: build step 2 "us.gcr.io/gae-runtimes/buildpacks/python37/builder:python37_20211201_3_7_12_RC00" failed: step exited with non-zero status: 145

我们的Requirements.txt如下。我们目前使用的是 Python 3.7 标准应用程序引擎

firebase_admin==3.0.0
sendgrid==6.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
jinja2==3.0.3
MarkupSafe==2.0.1
pytz==2021.3
Flask==2.0.2
twilio==6.46.0
httplib2==0.20.2
requests==2.24.0
requests_toolbelt==0.9.1
google-cloud-tasks==2.7.1
google-cloud-logging==1.15.1
googleapis-common-protos==1.54.0

请帮忙。在更新requirements.txt 文件之前,上述代码运行良好。我们尝试删除 Gunicorn 以允许系统根据文档获取最新版本here https://cloud.google.com/build/docs/view-build-results#viewing_build_results.

我们有一个子目录结构,用于存储控制器中的所有 .py 文件和模型中的数据库定义。我们的 main.py 有以下内容 -

sys.path.append(os.path.join(os.path.dirname(__file__), '../controllers'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../models'))

有谁知道如何调试这个错误 -Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')。这是什么意思?


版本 60.3.0setuptools有一个错误导致上述 AttributeError,请参阅:https://github.com/pypa/setuptools/issues/3002 https://github.com/pypa/setuptools/issues/3002

从那时起它就被 Pypi 拉走了:

抽出的文件始终会被忽略,除非它们是唯一与版本说明符匹配的文件,该版本说明符使用 ==(不带任何使其成为范围的修饰符,例如 .*)或 ===“固定”到精确版本。否则,应根据 PEP 440 匹配此版本说明符,以处理本地版本、零填充等内容。

Source: https://www.python.org/dev/peps/pep-0592/ https://www.python.org/dev/peps/pep-0592/

您现在可以做的就是显式传递 setuptools 包的版本,例如使用版本 60.2.0 或 60.3.1。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google 应用程序引擎部署失败 - 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”) 的相关文章

随机推荐