簡體   English   中英

Google 應用引擎部署失敗 - 查找“pip”的模塊規范時出錯(AttributeError:模塊“__main__”沒有屬性“__file__”)

[英]Google app engine deployment fails- Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')

我們正在使用命令提示符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 以允許系統獲取最新版本。

我們有一個子目錄結構,用於存儲控制器中的所有 .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__') 這是什么意思?

最新版本的setuptools已被 PyPi 拉出,您會收到上述錯誤。

被抽出的文件總是被忽略,除非它們是唯一匹配版本說明符的文件,該說明符使用 ==(沒有任何使其成為范圍的修飾符,例如。*)或 ===“固定”到確切版本。 否則,應按照 PEP 440 對本地版本、零填充等內容匹配此版本說明符。

資料來源: https://www.python.org/dev/peps/pep-0592/

您現在可以做的是明確傳遞 package 的版本。

您的 setuptools 版本可能會被刪除:

https://pypi.org/project/setuptools/60.3.0/

雖然不知道如何在沒有工作 pip 的情況下解決這個問題。

通過在安裝 pip-tools 之前安裝 setuptools 的先前版本 60.2.0 幫助我讓它運行。

pip install setuptools==60.2.0

Setuptools 60.3.1現已推出 GitHub 鏈接在這里

我在部署 Google Cloud Function 時遇到了同樣的問題。 錯誤

cloud function Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__'); Error ID: c84b3231

在注釋掉 requirements.txt 中的一些包后出現,但這並不重要,可能不會導致它。 我想這更多是谷歌存儲不穩定的問題,因為我工作的同一個雲 Function 在一段時間之前已經丟失了它的存檔,突然之間,不知從何而來,顯示:

Archive not found in the storage location cloud function

我沒有刪除或更改任何可能解釋這一點的內容,因為在存儲位置找不到存檔:Google Function會建議。

在這次崩潰之后,我手動添加了main.pyrequirements.txt ,並用備份中的代碼再次填充它們。 這工作了一段時間,但 Google 存儲中似乎存在一些普遍的不穩定性 - 始終保留已部署腳本的備份。

並且在得到這個pip這個問題的錯誤之后,已經不穩定的雲Function,等待一兩天,谷歌Function再次顯示

Archive not found in the storage location cloud function

If you run into this pip error in a Cloud Function, you might consider updating pip in the "requirements.txt" but if you are in such an unstable Cloud Function the better workaround seems to be to create a new Cloud Function and copy everything in那里。

pip錯誤可能只是表明源腳本(在這種情況下為requirements.txt )無法運行,因為源代碼不再完全嵌入或在 Google 存儲中丟失了一些嵌入。

或者您給該雲 Function 第二次機會並edit go 到Source選項卡,單擊 Dropdown Source code以選擇Inline Editor並手動添加main.pyrequirements.txtRuntime :Python)。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM