def findchilddirectory(self, parent: Union[str,Path], child: str, create: bool = False,…
- User
def find_child_directory(self, parent: Union[str,Path], child: str, create: bool = False, as_string: bool = True) -> Union[Path, str]: """ Finds a child directory within a given parent directory or optionally creates it if it doesn't exist.
Args: parent (str): The starting directory path. child (str): The target child directory name to find or create. create (bool): If True, creates the child directory if it does not exist. as_string (bool): If True, returns the path as a string; False returns Path Object. Returns: Union[Path, str]: A Path object or string of the found or created child directory, or None if not found/created. """ parent_path = Path(parent) child_path = parent_path / child if not child_path.is_dir() and create: try: child_path.mkdir(parents=True, exist_ok=True) except OSError as e: self.log_events(f"Error creating directory {child_path}: {e}", TroubleSgltn.Severity.WARNING, True) return "" return str(child_path) if as_string else child_pathFile "D:\ComfyUI-aki-v1.1\custom_nodes\Plush-for-ComfyUI\mng_json.py", line 153, in init self.customnodes_dir = self.find_child_directory(self.comfy_dir, 'custom_nodes', False, True) File "D:\ComfyUI-aki-v1.1\custom_nodes\Plush-for-ComfyUI\mng_json.py", line 404, in find_child_directory parent_path = Path(parent) File "D:\ComfyUI-aki-v1.1\python\lib\pathlib.py", line 960, in new self = cls._from_parts(args) File "D:\ComfyUI-aki-v1.1\python\lib\pathlib.py", line 594, in _from_parts drv, root, parts = self._parse_args(args) File "D:\ComfyUI-aki-v1.1\python\lib\pathlib.py", line 578, in _parse_args a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not NoneType
Cannot import D:\ComfyUI-aki-v1.1\custom_nodes\Plush-for-ComfyUI module for custom nodes: expected str, bytes or os.PathLike objec 怎么解决这个问题 ?
- Assistant
错误信息表示在尝试创建
Path对象时,给定的parent参数是None。这通常意味着调用find_child_directory函数时,没有正确传递parent参数,或者传递了一个为None的值。为了解决这个问题,您需要确保调用
find_child_directory时提供了正确的parent目录路径。下面是一些可能的解决步骤:-
检查调用
find_child_directory函数的代码。例如,检查self.comfy_dir是否已经被正确初始化,并且不是None。# Example of caller function def __init__(self, ...): # Make sure comfy_dir is initialized self.comfy_dir = 'some_valid_directory_path' self.customnodes_dir = self.find_child_directory(self.comfy_dir, 'custom_nodes', False, True) -
如果
parent参数是从另一个函数或变量获得的,确保那个函数或变量返回了正确的路径值,而不是None。 -
如果有必要,你可以在
find_child_directory函数的开始添加一个检查,确保parent不是None,例如:
-
- User
def init(self):
self.trbl = TroubleSgltn() # Get the directory where the script is located # Public properties self.script_dir = os.path.dirname(os.path.abspath(__file__)) self.script_parent, self.script_parent_dirname = self.findParent(self.script_dir) self.update_file = os.path.join(self.script_dir, 'update.json') self.config_file = os.path.join(self.script_dir, 'config.json') self.backup_dir = self.find_child_directory(self.script_dir, 'bkup', True, True) self.backup_config_path = os.path.join(self.backup_dir, 'config.json') self.comfy_dir = self.find_target_directory(self.script_dir, 'ComfyUI', True) self.customnodes_dir = self.find_child_directory(self.comfy_dir, 'custom_nodes', False, True) self.temp_dir = self.find_child_directory(self.script_dir, 'temp', True) self.log_dir = self.find_child_directory(self.script_dir, 'logs', True) self.log_file_name = "Plush-Events" #Private Properties self._config_bad = os.path.join(self.script_dir, 'config.bad') self._update_bad = os.path.join(self.script_dir, 'update.bad') 是在这里面调用的 - Assistant
Since you're encountering an error at the call to
self.find_child_directory(self.comfy_dir, 'custom_nodes', False, True), it's likely that the issue lies with the value ofself.comfy_dir. Ifself.comfy_dirisNone, that would cause theTypeErroryou're seeing whenfind_child_directorytries to create aPathobject usingPath(parent).It looks like the value of relies on . You should verify that is actually returning a valid directory path and not .