我们使用命令提示符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如下。我们目前正在使用Python3.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请help.The上面的代码在更新requirements.txt文件之前运行良好。根据Documents这里的说法,我们试图移除古尼科恩,以允许系统拾取最新的信息。
我们有一个子目录结构,它在控制器中存储所有.py文件,在模型中存储db定义。我们的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__')。这是什么意思?
发布于 2022-01-07 10:04:07
在部署Google函数时,我也遇到了同样的问题。误差
查找“pip”模块规范时出现云功能错误(AttributeError:模块'main‘没有属性'file');错误ID: c84b3231
在注释掉requirements.txt中的一些包后出现,但这并不重要,很可能不会导致它。我想这更像是谷歌存储系统(GoogleStorage)中的一个不稳定问题,因为我正在处理的那个云功能在不久前就丢失了它的存档,突然间,不知从哪冒出来的,显示:
在存储位置云函数中找不到存档
我并没有像在存储位置找不到存档: Google函数所建议的那样,删除或更改任何可能解释这一点的内容。尽管这个答案有一个非常有趣的猜测,至少可以解释第一次出现"Archive“错误,从而使CF变得不稳定:我可能在浏览Google时更改了存储桶的时区城市。这是太久以前,但我知道我浏览了GS,因此,我不能排除这一点。引用:“如果GCS桶的区域与云功能区域不匹配,则存档未找到的错误也可能发生。”
在这个"Archive“崩溃之后,我手动添加了main.py和requirements.txt,并再次填充了备份中的代码。这在一段时间内起了作用,但谷歌存储似乎存在一些普遍的不稳定性。因此,始终保留已部署脚本的备份。
然后,在得到这个问题的pip错误后,在已经不稳定的云函数中等待一两天之后,Google函数再次显示
在存储位置云函数中找不到存档
如果您在云函数中遇到这个pip错误,您可能会考虑在"requirements.txt“,但是如果您处于这样一个不稳定的云函数中,更好的解决方法似乎是创建一个新的云函数并将所有内容复制到其中。
pip错误可能只是表明源脚本(在本例中是requirements.txt )无法运行,因为源代码不再被完全嵌入,或者已经在Google中丢失了一些嵌入。
或者给这个云函数第二次机会,edit,转到Source选项卡,点击下拉Source code选择Inline Editor,手动添加main.py和requirements.txt (Runtime:Python)。

发布于 2022-01-06 14:56:28
setuptools的60.3.0版本有一个导致上述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。
发布于 2022-01-06 10:22:08
通过在安装setuptools之前安装上一个版本60.2.0的setuptools,可以帮助我运行它。
pip install setuptools==60.2.0
https://stackoverflow.com/questions/70602290
复制相似问题