1.1 问题描述:
我在尝试将 Windows 机器导出的学习器放到linux服务器中进行加载时,遇到了一个问题。这个问题似乎是 learner.path 被序列化为 pathlib.WindowsPath 并且当我尝试反序列化时系统无法实例化。
即出现如下错误:
NotImplementedError: cannot instantiate 'WindowsPath' on your system
1.2 解决方案:
只需要在你执行的python文件开头,加上下面几段代码即可:
import platform
import pathlib
plt = platform.system()
if plt != 'Windows':
pathlib.WindowsPath = pathlib.PosixPath
2.1 问题描述
反之,如果出现“NotImplementedError: cannot instantiate ‘PosixPath’ on your system”错误提示
即:
NotImplementedError: cannot instantiate 'PosixPath' on your system
2.2 解决方案:
只需采取相反的措施即可解决:
import platform
import pathlib
plt = platform.system()
if plt == 'Windows':
pathlib.PosixPath = pathlib.WindowsPath