PySide6运行空pyproject时触发JSONDecoderError问题求助
问题描述
在Qt Creator中基于Qt 6.5.2创建空的Qt Quick Application(Python版本),编辑.pyproject文件为以下内容:
{ "files": [ "main.py", "main.qml" ], "qmlImportPath": [ "path/to/my/qml/directory" ] }
构建项目时触发以下异常:
Traceback (most recent call last): File "C:\Users\ASUS\Documents\Qt Project\untitled\venv\Lib\site-packages\PySide6\scripts\project.py", line 240, in <module> project = Project(project_file) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Documents\Qt Project\untitled\venv\Lib\site-packages\PySide6\scripts\project.py", line 58, in __init__ self.project = ProjectData(project_file=project_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Documents\Qt Project\untitled\venv\Lib\site-packages\PySide6\scripts\project\project_data.py", line 30, in __init__ pyproject = json.load(pyf) ^^^^^^^^^^^^^^ File "C:\Users\ASUS\anaconda3\envs\ml\Lib\json\__init__.py", line 293, in load return loads(fp.read(), ^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\anaconda3\envs\ml\Lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\anaconda3\envs\ml\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\anaconda3\envs\ml\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
即使通过Ctrl+Z撤销对.pyproject的编辑,异常仍持续存在。
解决方案
检查
.pyproject文件完整性
撤销操作可能未完全恢复文件内容,直接打开.pyproject确认它是标准JSON格式。默认内容应该类似:{ "files": [ "main.py", "main.qml" ] }若文件为空、有乱码或格式错误,手动输入上述内容并保存。
清理Qt Creator缓存
Qt Creator可能缓存了损坏的配置,按以下步骤操作:- 关闭Qt Creator
- 删除项目目录下的
.qmake.stash和Makefile文件 - 进入Windows缓存目录
C:\Users\<你的用户名>\AppData\Local\QtProject\qtcreator,删除对应项目的缓存文件夹 - 重新打开Qt Creator并构建项目
验证Python环境匹配性
确保虚拟环境中PySide6版本与Qt 6.5.2一致,运行命令检查:pip show PySide6若版本不匹配,卸载后重装对应版本:
pip uninstall PySide6 -y pip install PySide6==6.5.2重新生成项目文件
若以上方法无效,删除当前.pyproject文件,在Qt Creator中右键项目 ->Add New...-> 选择Python分类下的Project File,重新生成标准的.pyproject。
内容的提问来源于stack exchange,提问作者Kamichanw
相关产品推荐
相关产品推荐

