1
from sklearn.externals import joblib 
  
import pickle
import pandas as pd
# Load the model from the file 
knn_from_joblib = joblib.load('lm.pkl')  
  
X_test= pd.read_excel('input.xlsx')
# Use the loaded model to make predictions 
final_Data= X_test

predictions = knn_from_joblib.predict(X_test) 
predictions
final_Data['Predicted Yield']= predictions

final_Data.to_excel("predictions.xlsx")  

When I make exe from this file and run that exe file I got the error below

enter image description here

when I run .py file from IDE it runs fine.

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Does this answer your question? [ImportError: cannot import name 'joblib' from 'sklearn.externals'](https://stackoverflow.com/questions/61893719/importerror-cannot-import-name-joblib-from-sklearn-externals) – Divyansh Tiwari Sep 06 '20 at 16:32
  • I tried but more errors occurs then, when I run .py code in IDE like Spyder it works, but not in pyinstaller – Arshbir Sandhu Sep 07 '20 at 06:07

2 Answers2

0

Try giving 'sklearn.externals' in hiddenimports list in the spec file like below:

a = Analysis( ...
         hiddenimports=['sklearn.externals']
         ...
         )
DesiKeki
  • 656
  • 8
  • 9
-1

The import from sklearn is missing. when sklearn try to import joblib,it doesn't find the file there. when you run from IDE, check where the joblib is located. if you find it, keep it in the path from where sklearn can import it. In your case, it is local/temp/external.. then recreate the exe file.

Groot
  • 171
  • 13
  • can you elaborate please, Give some detailed steps – Arshbir Sandhu Sep 07 '20 at 06:07
  • you need to locate joblib . just search from where sklearn is importing joblib. the attached error suggest that sklearn is not able to find joblib. so, look for joblib, and put it in proper directory from where sklearn can import it before creating exe file. – Groot Sep 07 '20 at 11:18