Jac*_*man 18 python google-app-engine google-app-engine-python
我们使用命令提示符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
Run Code Online (Sandbox Code Playgroud)
我们的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
Run Code Online (Sandbox Code Playgroud)
请帮忙。在更新requirements.txt 文件之前,上述代码运行良好。我们尝试删除 Gunicorn 以允许系统根据此处的文档获取最新版本。
我们有一个子目录结构,用于存储控制器中的所有 .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'))
Run Code Online (Sandbox Code Playgroud)
有谁知道如何调试这个错误 - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')。这是什么意思?
小智 9
版本 60.3.0setuptools有一个错误导致上述 AttributeError,请参阅:https ://github.com/pypa/setuptools/issues/3002
从那时起它就被 Pypi 拉走了:
抽出的文件始终会被忽略,除非它们是唯一与版本说明符匹配的文件,该版本说明符使用 ==(不带任何使其成为范围的修饰符,例如 .*)或 ===“固定”到精确版本。否则,应根据 PEP 440 匹配此版本说明符,以处理本地版本、零填充等内容。
来源: https: //www.python.org/dev/peps/pep-0592/
您现在可以做的就是显式传递 setuptools 包的版本,例如使用版本 60.2.0 或 60.3.1。
我在部署 Google Cloud Function 时遇到了同样的问题。错误
云函数查找“pip”的模块规范时出错(AttributeError:模块“ main ”没有属性“ file ”);错误 ID:c84b3231
在注释掉requirements.txt中的一些包后出现,但这并不重要,并且可能不会导致它。我想这更多是Google Storage 不稳定的问题,因为我正在开发的同一个云功能已经在一段时间之前丢失了其存档,突然之间,不知从何而来,显示:
在存储位置云功能中找不到存档
我没有删除或更改任何可能解释这一点的内容,因为在存储位置中找不到存档:Google Function会建议。尽管这个答案有一个非常有趣的猜测,至少可以解释第一次出现“未找到存档”错误并从而使 CF 不稳定的情况:我可能在浏览 Google Storage 期间更改了存储桶的时区城市。虽然已经过去很久了,但我知道我浏览过 GS,因此,我不能排除这一点。引用:“如果 GCS 存储桶的区域与您的云功能区域不匹配,也可能会出现[未找到存档错误]。”
在“找不到存档”崩溃之后,我手动添加main.py并requirements.txt再次使用备份中的代码填充它们。这工作了一段时间,但 Google 存储似乎存在一些普遍的不稳定。因此,请始终保留已部署脚本的备份。
然后,在pip已经不稳定的云函数中得到这个问题的错误后,等待一两天,谷歌函数再次显示
在存储位置云功能中找不到存档
pip如果您在云函数中遇到此错误,您可能会考虑在“requirements.txt”中进行更新pip,但如果您处于如此不稳定的云函数中,更好的解决方法似乎是创建一个新的云函数并复制其中的所有内容。
该pip错误可能只是表明源脚本(在本例中为 )requirements.txt无法运行,因为源代码不再完全嵌入或丢失了 Google 存储中的一些嵌入。
或者您给该云函数第二次机会edit,然后转到Source选项卡,单击下拉菜单Source code进行选择并手动Inline Editor添加( :Python)。main.pyrequirements.txtRuntime
| 归档时间: |
|
| 查看次数: |
2112 次 |
| 最近记录: |