简体   繁体   English

使用 PyInstaller 在 MSYS2/MinGW 中编译 GTK 软件时出现问题

[英]Issues compiling GTK software in MSYS2/MinGW with PyInstaller

I had a year old version of MSYS2/MinGW that was using PyInstaller with Python3.7 to compile a C GTK application in Windows (python was needed for a plotting script) and everything worked fine until pacman refused to update any packages since I kept getting the error: I had a year old version of MSYS2/MinGW that was using PyInstaller with Python3.7 to compile a C GTK application in Windows (python was needed for a plotting script) and everything worked fine until pacman refused to update any packages since I kept getting错误:

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.

I looked those up and the general response for it is: "The issue is usually provoked when you don't maintain your system at regular intervals - and I am not thinking yearly - because such neglect will often result in similar problems. The issue stems from a change in pacman code..."我查了一下,一般的反应是:“这个问题通常是在你没有定期维护你的系统时引发的——我不是每年都在考虑——因为这种忽视通常会导致类似的问题。问题源于来自 pacman 代码的更改……”

So I decided to start from a fresh MSYS2 install and used the following lines from both an MSYS2 shell and a MinGW-x64 shell, and each of them fails at a different point:因此,我决定从全新的 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

In the case of the MSYS2 shell, the pip install pyinstaller fails with:在 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.

An internet search shows this issue coming up on the github page for PyInstaller and a post here, neither of which were remotely enlightening:互联网搜索显示此问题出现在 PyInstaller 的 github 页面和此处的帖子中,两者都没有远程启发:

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

How to fix: PyInstaller in MSYS2 MinGW 'Your platform is not yet supported' 如何修复:MSYS2 MinGW 中的 PyInstaller '您的平台尚不受支持'

In the case of a MinGW shell, I can install everything fine, but I cannot compile the C code because I get the error:在 MinGW shell 的情况下,我可以安装一切正常,但我无法编译 C 代码,因为我收到错误:

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

Which means that MinGW doesn't know where to look for this file.这意味着 MinGW 不知道在哪里寻找这个文件。 It is located in:它位于:

msys64/usr/include/sys

but I suppose that only works for an MSYS2 shell?但我想这仅适用于 MSYS2 shell? And yet my year old MinGW shell will compile the C code without this error, but despite every effort (following the bash history for package installation for the working version, manually copying over package folders, on and on) I continue to come up against this error. And yet my year old MinGW shell will compile the C code without this error, but despite every effort (following the bash history for package installation for the working version, manually copying over package folders, on and on) I continue to come up against this错误。 Just copying the folder above into the MinGW include folder results in further issues and is clearly sloppy.只是将上面的文件夹复制到 MinGW 包含文件夹中会导致进一步的问题,并且显然是草率的。 I want a repeatable way to get this to work, and I have repeated the process outlined above on several computers and have got the exact same result every time - so I expect anyone starting with a fresh MSYS2 install will run up against the same problems.我想要一种可重复的方法来让它工作,我已经在几台计算机上重复了上面概述的过程,并且每次都得到完全相同的结果 - 所以我希望任何从新安装 MSYS2 开始的人都会遇到同样的问题。 Any help in getting this to run would be very much appreciated as I am getting frustrated with all of the dead ends.非常感谢任何帮助让它运行的帮助,因为我对所有的死胡同感到沮丧。

sys/wait.h isn't there in MinGW, but you can use the one from: https://github.com/win32ports/sys_wait_h sys/wait.h在 MinGW 中不存在,但您可以使用来自: https://github.com/win32ports/sys_wait_h

I was finally able to get this figured out.我终于能够弄清楚这一点。 The first thing to know is that the initial compiling must be done in the MSYS2 shell.首先要知道的是,初始编译必须在 MSYS2 shell 中完成。 Once you successfully compile it in the MSYS2 shell, you can then compile in the MINGW shell without issue.在 MSYS2 shell 中成功编译后,您就可以在 MINGW shell 中毫无问题地进行编译。 I am not sure why that is so, but I anticipated it would be the case.我不确定为什么会这样,但我预计会是这样。

I solved the PyInstaller issue by downloading Python 3.7 from http://repo.msys2.org/ and installing it using:我通过从http://repo.msys2.org/下载 Python 3.7 并使用以下方式安装它解决了 PyInstaller 问题:

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

I also needed Python 3.7 installed in Windows, and the path edited in my.bashrc file:我还需要在 Windows 中安装 Python 3.7,并在 my.bashrc 文件中编辑路径:

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

I am not sure if PyInstaller is compatible with Python 3.8 yet.我不确定 PyInstaller 是否与 Python 3.8 兼容。 I posted an issue to their GitHub page, and it is here for reference in case it is resolved:我在他们的 GitHub 页面上发布了一个问题,如果解决了,请在此处参考:

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

PyInstaller then worked, but I was met with another issue that I posted to Stack Overflow, but figured out as well. PyInstaller 然后工作了,但我遇到了另一个我发布到 Stack Overflow 的问题,但也发现了。 That is here:就是在这里:

MSYS2 gcc fatal error in cc1.exe: cygheap base mismatch detected cc1.exe 中的 MSYS2 gcc 致命错误:检测到 cygheap 基础不匹配

After that issue was resolved I could compile my program in MSYS2.解决该问题后,我可以在 MSYS2 中编译我的程序。 Switching over to a MINGW shell, I found that it now compiled there as well.切换到 MINGW shell,我发现它现在也在那里编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM