使用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外壳的情况下,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

如何修复:PyInstaller在MSYS2 MinGW';您的平台尚未得到支持';

在MinGW外壳的情况下,我可以很好地安装所有东西,但我无法编译C代码,因为我得到了错误:

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

这意味着MinGW不知道在哪里可以查找此文件。它位于:

msys64/usr/include/sys

但我想这只适用于MSYS2外壳?然而,我一岁的MinGWshell将在没有这个错误的情况下编译C代码,但尽管尽了一切努力(遵循工作版本的包安装的bash历史记录,手动复制包文件夹,等等(,我仍然会遇到这个错误。仅仅将上面的文件夹复制到MinGW include文件夹中就会导致进一步的问题,而且显然是草率的。我想要一种可重复的方法来实现这一点,我已经在几台计算机上重复了上面概述的过程,每次都得到了完全相同的结果——所以我希望任何刚开始安装MSYS2的人都会遇到同样的问题。如果有任何帮助,我将不胜感激,因为我对所有的死胡同都感到沮丧。

我终于弄明白了这一点。首先要知道的是,初始编译必须在MSYS2 shell中完成。一旦您在MSYS2 shell中成功编译它,您就可以在MINGW shell中编译而不会出现问题。我不知道为什么会这样,但我预计会是这样。

我通过从http://repo.msys2.org/并使用安装

pacman -U python-3.7.2-1-x86_64.pkg.tar

我还需要在Windows中安装Python 3.7,并在.bashrc文件中编辑路径:

export PYTHON_HOME=C:\Users\Leigh\AppData\Local\Programs\Python\Python37
export PATH="$PYTHON_HOME:$PYTHON_HOME\Scripts:$PATH"

我还不确定PyInstaller是否与Python 3.8兼容。我在他们的GitHub页面上发布了一个问题,它在这里供参考,以防问题得到解决:

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

PyInstaller随后工作了,但我遇到了另一个问题,我发布到了Stack Overflow,但也解决了。就在这里:

cc1.exe中的MSYS2 gcc致命错误:检测到cygheap基不匹配

在这个问题解决后,我可以在MSYS2中编译我的程序。切换到MINGW shell,我发现它现在也在那里编译。

sys/wait.h在MinGW中不存在,但您可以使用以下内容中的内容:https://github.com/win32ports/sys_wait_h

最新更新