首页 > 解决方案 > 使用 PyInstaller 在 MSYS2/MinGW 中编译 GTK 软件的问题

问题描述

我有一个旧版本的 MSYS2/MinGW,它使用 PyInstaller 和 Python3.7 在 Windows 中编译 C GTK 应用程序(绘图脚本需要 python)并且一切正常,直到 pacman 拒绝更新任何包,因为我不断得到错误:

error: hook /usr/share/libalpm/hooks/mingw-w64-x84_64-gtk-query-immodules-3.0.hook line 2: invalid value Path
error: hook /usr/share/libalpm/hooks/mingw-w64-x84_64-gtk-update-icon-cache.hook line 2: invalid value Path
Errors occurred, no packages were upgraded.

我查了一下,一般的反应是:“这个问题通常是在你没有定期维护你的系统时引发的——我不是每年都在考虑——因为这种忽视通常会导致类似的问题。问题源于来自 pacman 代码的更改……”

所以我决定从一个全新的 MSYS2 安装开始,并使用 MSYS2 shell 和 MinGW-x64 shell 中的以下行,它们中的每一个都在不同的点上失败:

pacman -Syu
pacman -Su
pacman -S nano
pacman -S mingw-w64-i686-gtk3
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gtk3 mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-gobject
pacman -S --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain git subversion mercurial mingw-w64-i686-cmake mingw-w64-x86_64-cmake
pacman -S python3-pip
pacman -S mingw-w64-x86_64-python3-pip
pacman -S msys2-devel
pacman -S mingw-w64-x86_64-glade
pacman -S mingw-w64-x86_64-gobject-introspection
pip install pyinstaller

在 MSYS2 shell 的情况下,pip install pyinstaller失败并显示:

# pip install pyinstaller
Collecting pyinstaller
  Using cached PyInstaller-3.6.tar.gz (3.5 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.exe /usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpd9hk1ekp
       cwd: /tmp/pip-install-ouq11vnr/pyinstaller
  Complete output (1 lines):
  Your platform is not yet supported. Please define constant PYDYLIB_NAMES for your platform.

互联网搜索显示此问题出现在 PyInstaller 的 github 页面和此处的帖子中,两者都没有远程启发:

https://github.com/pyinstaller/pyinstaller/issues/4542

如何修复:MSYS2 MinGW 中的 PyInstaller '您的平台尚不受支持'

在 MinGW shell 的情况下,我可以安装一切正常,但我无法编译 C 代码,因为我收到错误:

fatal error: sys/wait.h: No such file or directory
    7 | #include <sys/wait.h>
      |          ^~~~~~~~~~~~
compilation terminated.

这意味着 MinGW 不知道在哪里寻找这个文件。它位于:

msys64/usr/include/sys

但我想这只适用于 MSYS2 shell?然而,我一岁的 MinGW shell 将编译 C 代码而不会出现此错误,但尽管付出了一切努力(按照 bash 历史记录为工作版本安装包,手动复制包文件夹,不断地)我继续遇到这个问题错误。只是将上面的文件夹复制到 MinGW 包含文件夹中会导致进一步的问题,并且显然是草率的。我想要一种可重复的方法来让它工作,我已经在几台计算机上重复了上面概述的过程并且每次都得到完全相同的结果 - 所以我希望任何从新安装 MSYS2 开始的人都会遇到同样的问题。非常感谢任何帮助让它运行的帮助,因为我对所有的死胡同感到沮丧。

标签: pythoncmingwpyinstallermsys2

解决方案


sys/wait.hMinGW 中没有,但您可以使用来自:https ://github.com/win32ports/sys_wait_h


推荐阅读