with open() 报错FileNotFoundError: [Errno 2] No such file or directory

代码

原代码:

 with open('speed_pca.m', 'rb') as f:
 	speed_pca = joblib.load(‘speed_pca.m’)

报错代码

File "E:\Weater Routing\package\speed_calculate.py", line 155, in speed_BBMs
    with open('speed_pca.m', 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'speed_pca.m'

speed_pca.m与执行代码在同一文件夹package下,仍然报错。

问题原因

1.open对象要加路径
2.应该导入f而不是‘speed_pca.m’

解决方法

with open('E:\Weater Routing\package\speed_pca.m', 'rb') as f:
 	speed_pca = joblib.load(f)

你可能感兴趣的:(机器学习,python)