按照Towhee官网的快速入门照着写的代码,出现一系列Traceback (most recent call last):错误

按照Towhee官网的快速入门照着写的代码,出现一系列Traceback (most recent call last):错误
本人小白,参加项目想学习一下关于视频,音频的embedding降维,去Towhee官网简单学习了一下,照着官网的代码写的,出现这些错误,请求大佬指点:sob:

Jason990420
最佳答案

出错的原因类似如下

>>> from pathlib import Path
>>> path = Path('D:/')
>>> ' ' in path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'WindowsPath' is not iterable

Python 3.7subprocess 库中, 当 argWindowsPath 就会出错.

def list2cmdline(seq):
    ...
    for arg in seq:
    ...
        needquote = (" " in arg) or ("\t" in arg) or not arg

seq = ['git', 'clone', '-b', 'main', 'https://towhee.io/towhee/image-embedding-resnet50.git',
    WindowsPath('C:/Users/Jason/.towhee/pipelines/towhee/image_embedding_resnet50/main')]
list2cmdline(seq)

Python 3.8 以后, 每个 arg 都先经 os.fsdecode 函数处理后, 就不会出错了.

fsdecode(filename)

Decode filename (an os.PathLike, bytes, or str) from the filesystem encoding with ‘surrogateescape’ error handler, return str unchanged. On Windows, use ‘strict’ error handler if the file system encoding is ‘mbcs’ (which is the default encoding).

def list2cmdline(seq):
...
    for arg in map(os.fsdecode, seq):
...
        needquote = (" " in arg) or ("\t" in arg) or not arg

seq = ['git', 'clone', '-b', 'main', 'https://towhee.io/towhee/image-embedding-resnet50.git',
    WindowsPath('C:/Users/Jason/.towhee/pipelines/towhee/image_embedding_resnet50/main')]
list2cmdline(seq)

安装的是 3.8.103.9.9, 都确认 OK.

2年前 评论
Park (楼主) 2年前
讨论数量: 2
Jason990420

出错的原因类似如下

>>> from pathlib import Path
>>> path = Path('D:/')
>>> ' ' in path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'WindowsPath' is not iterable

Python 3.7subprocess 库中, 当 argWindowsPath 就会出错.

def list2cmdline(seq):
    ...
    for arg in seq:
    ...
        needquote = (" " in arg) or ("\t" in arg) or not arg

seq = ['git', 'clone', '-b', 'main', 'https://towhee.io/towhee/image-embedding-resnet50.git',
    WindowsPath('C:/Users/Jason/.towhee/pipelines/towhee/image_embedding_resnet50/main')]
list2cmdline(seq)

Python 3.8 以后, 每个 arg 都先经 os.fsdecode 函数处理后, 就不会出错了.

fsdecode(filename)

Decode filename (an os.PathLike, bytes, or str) from the filesystem encoding with ‘surrogateescape’ error handler, return str unchanged. On Windows, use ‘strict’ error handler if the file system encoding is ‘mbcs’ (which is the default encoding).

def list2cmdline(seq):
...
    for arg in map(os.fsdecode, seq):
...
        needquote = (" " in arg) or ("\t" in arg) or not arg

seq = ['git', 'clone', '-b', 'main', 'https://towhee.io/towhee/image-embedding-resnet50.git',
    WindowsPath('C:/Users/Jason/.towhee/pipelines/towhee/image_embedding_resnet50/main')]
list2cmdline(seq)

安装的是 3.8.103.9.9, 都确认 OK.

2年前 评论
Park (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!