NotImplementedError: cannot instantiate ‘PosixPath‘ on your system 读取pickle文件错误
·
报错内容
raise NotImplementedError(“cannot instantiate %r on your system”
NotImplementedError: cannot instantiate ‘PosixPath’ on your system’‘’
报错原因:
模型在linux训练后windows路径加载错误(路径错误问题)
解决方案1:在调用PosixPath时修改
- windows系统读取时,报错:NotImplementedError: cannot instantiate ‘PosixPath’ on your system
在代码的最前面加上:
import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
- Linux系统读取时,报错:NotImplementedError: cannot instantiate ‘WindowsPath’ on your system
在代码的最前面加上:
import pathlib
pathlib.WindowsPath = pathlib.PosixPath
解决方案2:修改…\anaconda3\envs\ADP\lib\pathlib.py文件
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args)
#添加代码
if type(self) == PosixPath:
cls = WindowsPath
self = cls._from_parts(args)
if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
return self
如图:
更多推荐




所有评论(0)