簡體   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錯誤:

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? 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錯誤。 只是將上面的文件夾復制到 MinGW 包含文件夾中會導致進一步的問題,並且顯然是草率的。 我想要一種可重復的方法來讓它工作,我已經在幾台計算機上重復了上面概述的過程,並且每次都得到完全相同的結果 - 所以我希望任何從新安裝 MSYS2 開始的人都會遇到同樣的問題。 非常感謝任何幫助讓它運行的幫助,因為我對所有的死胡同感到沮喪。

sys/wait.h在 MinGW 中不存在,但您可以使用來自: https://github.com/win32ports/sys_wait_h

我終於能夠弄清楚這一點。 首先要知道的是,初始編譯必須在 MSYS2 shell 中完成。 在 MSYS2 shell 中成功編譯后,您就可以在 MINGW shell 中毫無問題地進行編譯。 我不確定為什么會這樣,但我預計會是這樣。

我通過從http://repo.msys2.org/下載 Python 3.7 並使用以下方式安裝它解決了 PyInstaller 問題:

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

我還需要在 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"

我不確定 PyInstaller 是否與 Python 3.8 兼容。 我在他們的 GitHub 頁面上發布了一個問題,如果解決了,請在此處參考:

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

PyInstaller 然后工作了,但我遇到了另一個我發布到 Stack Overflow 的問題,但也發現了。 就是在這里:

cc1.exe 中的 MSYS2 gcc 致命錯誤:檢測到 cygheap 基礎不匹配

解決該問題后,我可以在 MSYS2 中編譯我的程序。 切換到 MINGW shell,我發現它現在也在那里編譯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM