使用飞桨paddlenlp的Taskflow API报错 RuntimeError: C:\Users\*** mkdir failed!

在github提出issues后,开发者很友好的帮助解决了这个问题。
为paddlenlp的工作人员点个赞!

执行代码如下


from paddlenlp import Taskflow

tag = Taskflow("pos_tagging")

不光是pos_tagging,其它Taskflow的任务如word_segmentation、ner等也不能使用。

报错如下

Traceback (most recent call last):
  File "D:/机器学习/paddlenlp/test.py", line 3, in 
    tag = Taskflow("pos_tagging")
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddlenlp\taskflow\taskflow.py", line 572, in __init__
    **self.kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddlenlp\taskflow\pos_tagging.py", line 53, in __init__
    super().__init__(task=task, model=model, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddlenlp\taskflow\lexical_analysis.py", line 121, in __init__
    self._get_inference_model()
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddlenlp\taskflow\task.py", line 247, in _get_inference_model
    self._convert_dygraph_to_static()
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddlenlp\taskflow\task.py", line 268, in _convert_dygraph_to_static
    paddle.jit.save(static_model, save_path)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\dygraph\jit.py", line 631, in wrapper
    func(layer, path, input_spec, **configs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\dygraph\base.py", line 51, in __impl__
    return func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\dygraph\jit.py", line 993, in save
    clip_extra=configs.clip_extra)
  File "D:\anaconda3\envs\paddle\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\framework.py", line 443, in __impl__
    return func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\io.py", line 1460, in save_inference_model
    save_persistables(executor, save_dirname, main_program, params_filename)
  File "D:\anaconda3\envs\paddle\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\framework.py", line 425, in __impl__
    return func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\io.py", line 737, in save_persistables
    filename=filename)
  File "D:\anaconda3\envs\paddle\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\framework.py", line 425, in __impl__
    return func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\io.py", line 376, in save_vars
    filename=filename)
  File "D:\anaconda3\envs\paddle\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\framework.py", line 425, in __impl__
    return func(*args, **kwargs)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\io.py", line 431, in save_vars
    executor.run(save_program)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\executor.py", line 1299, in run
    six.reraise(*sys.exc_info())
  File "D:\anaconda3\envs\paddle\lib\site-packages\six.py", line 719, in reraise
    raise value
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\executor.py", line 1295, in run
    return_merged=return_merged)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\executor.py", line 1464, in _run_impl
    return new_exe.run(list(feed.keys()), fetch_list, return_numpy)
  File "D:\anaconda3\envs\paddle\lib\site-packages\paddle\fluid\executor.py", line 547, in run
    tensors = self._new_exe.run(feed_names, fetch_list)._move_to_list()
RuntimeError: C:\Users\***(中文)  mkdir failed!

关键是RuntimeError: C:\Users\***(中文) mkdir failed!
这里看下你的用户名是不是中文

win11创建用户,用户名输入中文后的痛苦!

解决方法

tag = Taskflow("pos_tagging", home_path="xxxx")

手动指定home_path,然后就可以成功运行了。

你可能感兴趣的:(paddlepaddle,python,人工智能)