Pickle 找不到我不使用的模塊? (Pickle can't find module that I am not using?)


問題描述

Pickle 找不到我不使用的模塊? (Pickle can't find module that I am not using?)

我有一個使用這些模塊生成模型的腳本。

import pandas as pd
import seaborn as sns
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.model_selection import RandomizedSearchCV
from sklearn.metrics import accuracy_score
from sklearn.ensemble import GradientBoostingClassifier
from imblearn.over_sampling import RandomOverSampler
from datetime import datetime
import pickle

然後當我解開模型時,我得到:

ImportError: No module named _gb

我非常困惑,問題可能是什麼是嗎?

我試過了& 我可以在 Python shell 中手動導入所有這些模塊

非常感謝

  File "/data/keenek1/production/ncx3_nps.py", line 232, in <module>
    model_det = pickle.load(file)
  File "/app/anaconda2/lib/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/app/anaconda2/lib/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/app/anaconda2/lib/python2.7/pickle.py", line 1096, in load_global
    klass = self.find_class(module, name)
  File "/app/anaconda2/lib/python2.7/pickle.py", line 1130, in find_class
    __import__(module)
ImportError: No module named _gb

參考解法

方法 1:

This happens when saving and loading occur in different environments.

I believe for Pickle to work correctly all modules related to the model have to have the same version when pickling and unpickling; python version and the operating system have to be the same.

No module named _gb error specifically can occur when a model saved in Windows is loaded in Linux environment.

(by kikee1222Ap31)

參考文件

  1. Pickle can't find module that I am not using? (CC BY‑SA 2.5/3.0/4.0)

#Python #python-3.x #pickle






相關問題

如何從控制台中導入的文件中訪問變量的內容? (How do I access the contents of a variable from a file imported in a console?)

在 python 3.5 的輸入列表中添加美元符號、逗號和大括號 (Adding dollar signs, commas and curly brackets to input list in python 3.5)

為 KeyError 打印出奇怪的錯誤消息 (Strange error message printed out for KeyError)

django 1.9 中的 from django.views.generic.simple import direct_to_template 相當於什麼 (What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9)

查詢嵌入列表中的數組 (Querying for array in embedded list)

如何在 Python 中搜索子字符串是否在二進製文件中? (How to search if a substring is into a binary file in Python?)

為什麼要避免 while 循環? (Why avoid while loops?)

使用python的json模塊解析json請求 (Parse a json request using json module of python)

為什麼使用 py2app 模塊創建 mac 文件時出現錯誤? (Why i am getting Error when creating mac file using py2app module?)

當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)

如何繪製一條帶斜率和一個點的線?Python (How to plot a line with slope and one point given? Python)

Pickle 找不到我不使用的模塊? (Pickle can't find module that I am not using?)







留言討論