TypeError: expected str, bytes or os.PathLike object, not NoneType

博客提到TypeError: expected str, bytes or os.PathLike object, not NoneType错误,工作平台为Ubuntu 16.04.4 LTS,版本Release为16.04 (xenial),并给出了解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TypeError: expected str, bytes or os.PathLike object, not NoneType

Platform and which version I’m working on:
Description: Ubuntu 16.04.4 LTS
Release: 16.04 (xenial)

[...]
58477 INFO: Loading module hook "hook-gevent.monkey.py"...
58612 INFO: Looking for ctypes DLLs
58982 WARNING: library user32 required via ctypes not found
59330 INFO: Analyzing run-time hooks ...
59365 INFO: Including run-time hook 'pyi_rth__tkinter.py'
59367 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
59370 INFO: Including run-time hook 'pyi_rth_pkgres.py'
59371 INFO: Including run-time hook 'pyi_rth_traitlets.py'
59372 INFO: Including run-time hook 'pyi_rth_qt5.py'
59373 INFO: Including run-time hook 'pyi_rth_mplconfig.py'
59374 INFO: Including run-time hook 'pyi_rth_mpldata.py'
59437 INFO: Looking for dynamic libraries
63980 INFO: Looking for eggs
63980 INFO: Using Python library ~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/scipy/linalg/../../../../libpython3.6m.so.1.0
64015 INFO: Warnings written to ~/build/__init__/warn__init__.txt
64298 INFO: Graph cross-reference written to ~/build/__init__/xref-__init__.html
64447 INFO: checking PYZ
64447 INFO: Building PYZ because out00-PYZ.toc is non existent
64447 INFO: Building PYZ (ZlibArchive) ~/build/__init__/out00-PYZ.pyz
67927 INFO: Building PYZ (ZlibArchive) ~/build/__init__/out00-PYZ.pyz completed successfully.
68011 INFO: checking PKG
68011 INFO: Building PKG because out00-PKG.toc is non existent
68011 INFO: Building PKG (CArchive) out00-PKG.pkg
Traceback (most recent call last):
  File "~/Softwares/anaconda3/5.0.0/bin/pyinstaller", line 11, in <module>
    load_entry_point('PyInstaller==3.4.dev0+2611919ba', 'console_scripts', 'pyinstaller')()
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/__main__.py", line 94, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 791, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 737, in build
    exec(text, spec_namespace)
  File "<string>", line 26, in <module>
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/api.py", line 411, in __init__
    strip_binaries=self.strip, upx_binaries=self.upx,
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/api.py", line 196, in __init__
    self.__postinit__()
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/datastruct.py", line 161, in __postinit__
    self.assemble()
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/site-packages/PyInstaller/building/api.py", line 273, in assemble
    pylib_name = os.path.basename(bindepend.get_python_library_path())
  File "~/Softwares/anaconda3/5.0.0/lib/python3.6/posixpath.py", line 144, in basename
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

解决办法:
这里写图片描述

LD_LIBRARY_PATH=${CONDA_PREFIX}/lib pyinstaller
### LabelImg 中 `TypeError: expected str, bytes or os.PathLike object, not NoneType` 的解决方案 此错误通常发生在尝试保存标注文件时,程序试图操作一个路径变量 (`self.filePath`),但由于该变量未被正确定义或赋值而为 `NoneType` 类型。以下是详细的分析与解决方法: #### 错误原因 当调用 `os.path.dirname(self.filePath)` 函数时,如果 `self.filePath` 是 `None` 而不是预期的字符串或其他兼容类型的对象,则会触发上述 `TypeError`[^2]。 --- #### 解决方案一:检查并修复代码逻辑 在 `labelImg.py` 文件中定位到第 1374 行附近的相关代码片段: ```python imgFileDir = os.path.dirname(self.filePath) ``` 此处假设 `self.filePath` 已经是一个有效的路径字符串。然而,在某些情况下(例如尚未加载图像),它可能仍为 `None`。可以通过添加条件判断来防止此类错误发生: ```python if self.filePath is not None and isinstance(self.filePath, (str, os.PathLike)): imgFileDir = os.path.dirname(self.filePath) else: raise ValueError("FilePath must be a valid string or PathLike object.") ``` 通过这种方式可以有效避免因 `self.filePath` 值不合法而导致的崩溃问题[^3]。 --- #### 解决方案二:确认数据集配置无误 对于 YOLO 或其他框架下的数据处理流程而言,确保所使用的训练/测试集合目录命名严格遵循官方文档规定非常重要;任何细微差异都可能导致类似异常情况的发生[^4]。因此建议按照如下结构重新整理项目资源树形图后再试一次运行脚本看看效果如何改善: ``` dataset/ ├── images/ │ ├── train/ │ └── val/ └── labels/ ├── train/ └── val/ ``` 同时记得清除旧缓存(`cache`)以防残留信息干扰新版本执行过程中的正常解析行为。 --- #### 总结说明 以上两种途径分别针对源码层面以及外部依赖环境两方面提供了可行性的调整措施以应对当前遇到的技术难题。实际应用过程中可以根据具体情况选择适合自己的办法加以实施从而彻底消除这个恼人的提示消息! ---
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值