简体   繁体   中英

IOError [Errno 2] Pickle error in python

I have a file analyze.py where I have :

model = joblib.load('svm-model-1.pkl')

When I run my python server where analyze.py is called, I get the following error:

File "/usr/lib/python2.7/dist-packages/joblib/numpy_pickle.py", line 443, in load
        with open(filename, 'rb') as file_handle:
    IOError: [Errno 2] No such file or directory: '/static/analysis/sleep_apnea_IHR_web_Integration/svm-model-1.pkl'

analyze.py and svm-model-1.pkl are both in the same directory. So, it is not the path issue. Could you tell how to solve this error?

Simplest solution is to use the full path. Either hard code it:

model = joblib.load('/path/to/svm-model-1.pkl')

or construct it:

import os
location = '/the/path'
fullpath = os.path.join(location, 'svm-model-1.pkl')
model = joblib.load(fullpath)

If that fails, as commented by immortal you should check the permissions.

Pickel should help easily:

a=[1,2,3,4]
file=open("file","wb")
import pickle
pickle.dump(a,file)
file.close()
file=open("file","rb")
b=pickle.load(file)
file.close()
print(b)

will print give result as

[1,2,3,4]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM