App下載

Python無法讀取pickle文件在云應(yīng)用運(yùn)行 TypeError: __cinit__()怎么處理?

猿友 2021-07-22 11:40:17 瀏覽數(shù) (2593)
反饋

有一個我部署到GCP云運(yùn)行快速API應(yīng)用程序,直到昨,它一直工作得很好,我真的不知道哪里出了問題。當(dāng)我讀取.pkl文件時,問題似乎從這一行開始。

?model = pickle.load(open(os.path.join('models', 'appartementen.pkl'), 'rb'))?

追溯:

    File "pandas/_libs/internals.pyx", line 572, in pandas._libs.internals.BlockManager.__cinit__: TypeError: __cinit__() takes at least 2 positional arguments (0 given) at <module> (/app/src/api/util.py:25)
at <module> (/app/src/api/main.py:8) at
    _call_with_frames_removed (<frozen importlib._bootstrap>:219) at exec_module (<frozen importlib._bootstrap_external>:728) 
at _load_unlocked (<frozen importlib._bootstrap>:677) 
at _find_and_load_unlocked (<frozen importlib._bootstrap>:967) 
at _find_and_load (<frozen importlib._bootstrap>:983) 
at _gcd_import (<frozen importlib._bootstrap>:1006) 
at import_module (/usr/local/lib/python3.7/importlib/__init__.py:127) 
at import_app (/usr/local/lib/python3.7/site-packages/gunicorn/util.py:358) at load_wsgiapp (/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py:39) 
at load (/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py:49) 
at wsgi (/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py:67) 
at load_wsgi (/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py:144) 
at init_process (/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py:119) 
at spawn_worker (/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py:583)

請注意,當(dāng)我在本地部署此應(yīng)用程序時,一切都很順利。

我的多克檔案:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
WORKDIR /app
COPY . ./
COPY src ./src/
COPY models ./models/
RUN pip install -r requirements.txt
COPY setup.py ./
CMD exec gunicorn src.api.main:app

如何部署到云運(yùn)行:

gcloud builds submit --tag gcr.io/project-id/api --timeout=3600

gcloud run deploy api --image gcr.io/project-id/api --platform managed --project=project-id --region=europe-west4

requirements.txt:

fastapi==0.63.0
google-cloud-bigquery[bqstorage,pandas]==1.24.0
sentry_sdk==1.0.0
xgboost==1.3.3
scikit-learn==0.23.1
shap==0.39.0
matplotlib==3.4.1

我嘗試使用相同的版本根據(jù)這個建議,但問題仍然存在。scikit-learn

解決方法:

可能是對象的版本和容器版本之間不兼容,但恢復(fù)該版本對我有用。所以:pandaspandaspandas1.2.51.3.0

pip uninstall pandas
pip install pandas==1.2.5


0 人點(diǎn)贊