Windows11下PySide6部署工具pyside6-deploy运行报错的解决求助
我想要部署一个用Qt for Python(PySide6 + QML)创建的应用。当我在项目文件夹的cmd中运行pyside6-deploy命令时,出现了如下错误:
'pyside6-deploy' is not recognized as an internal or external command, operable program or batch file.
我尝试把deploy.py的路径(C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy.py)添加到PATH中,但还是无法正常运行。
请问我需要怎么做才能让pyside6-deploy命令正常工作?
我的操作系统是Windows 11
补充编辑内容
我把PATH修正为:C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\
PySide6已经安装完成:
我没有使用虚拟环境,因为这台电脑专门用来折腾Qt,所有项目环境都是一致的,这样用起来也方便。
现在deploy.py可以运行了,但又出现了新的错误:
C:\DANE\QtProjects\test3d_1>deploy.py You are not using a virtual environment. pyside6-deploy needs to install a few Python packages for deployment to work seamlessly. Proceed? [Y/n]Y 'pyside6-qmlimportscanner' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\commands.py", line 25, in run_command output = subprocess.check_output(command, shell=is_windows) File "C:\Program Files\Python313\Lib\subprocess.py", line 472, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ **kwargs).stdout ^^^^^^^^^ File "C:\Program Files\Python313\Lib\subprocess.py", line 577, in run raise CalledProcessError(retcode, process.args, output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['pyside6-qmlimportscanner', '-rootPath', 'C:\\DANE\\QtProjects\\test3d_1', '-exclude', 'site-packages', '-exclude', 'deployment', '-exclude', '.qtcreator', '-exclude', 'build', '-exclude', 'dist', '-exclude', 'tests', '-exclude', 'doc', '-exclude', 'docs', '-exclude', 'examples']' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy.py", line 214, in <module> main(args.main_file, args.name, args.config_file, args.init, args.loglevel, args.dry_run, ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ args.keep_deployment_files, args.force, args.extra_ignore_dirs, args.extra_modules, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ args.mode) ^^^^^^^^^^ File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy.py", line 109, in main config = DesktopConfig(config_file=config_file, source_file=main_file, python_exe=python.exe, dry_run=dry_run, existing_config_file=config_file_exists, extra_ignore_dirs=extra_ignore_dirs, mode=mode, name=name) File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\config.py", line 420, in __init__ super().__init__(config_file, source_file, python_exe, dry_run, existing_config_file, ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ extra_ignore_dirs, name=name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\config.py", line 166, in __init__ self.excluded_qml_plugins = self._find_excluded_qml_plugins() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\config.py", line 368, in _find_excluded_qml_plugins self.qml_modules = set(run_qmlimportscanner(project_dir=self.project_dir, ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dry_run=self.dry_run)) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\commands.py", line 58, in run_qmlimportscanner _, json_string = run_command(command=cmd, dry_run=False, fetch_output=True) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6\scripts\deploy_lib\commands.py", line 33, in run_command raise RuntimeError( ...<2 lines>... ) RuntimeError: [DEPLOY] Command pyside6-qmlimportscanner -rootPath C:\DANE\QtProjects\test3d_1 -exclude site-packages -exclude deployment -exclude .qtcreator -exclude build -exclude dist -exclude tests -exclude doc -exclude docs -exclude examples failed with error Command '['pyside6-qmlimportscanner', '-rootPath', 'C:\\DANE\\QtProjects\\test3d_1', '-exclude', 'site-packages', '-exclude', 'deployment', '-exclude', '.qtcreator', '-exclude', 'build', '-exclude', 'dist', '-exclude', 'tests', '-exclude', 'doc', '-exclude', 'docs', '-exclude', 'examples']' returned non-zero exit status 1. and return_code1
我在PySide6文件夹里找到了qmlimportscanner.exe,于是把C:\Users\danie\AppData\Roaming\Python\Python313\site-packages\PySide6也添加到了PATH中,但还是没用——程序找的是pyside6-qmlimportscanner而不是qmlimportscanner。
备注:内容来源于stack exchange,提问作者Daniel

