TransparentLC/realesrgan-gui

Automated build 20240602-060617版本,M1无法打开

Opened this issue · 13 comments

M1无法打开,无提示直接退出

由于我没有运行 macOS 的设备,因此可能无法处理和 macOS 相关的使用问题。

只能看其他的 macOS 甚至是 M1 的用户有没有碰到类似的问题了。

使用M1编译,命令用的readme里面的:
curl -L https://raw.githubusercontent.com/TransparentLC/realesrgan-gui/master/macos-build-script.sh | bash

提示:
jiaoting@JT-MacminiM1 ~ % curl -L https://raw.githubusercontent.com/TransparentLC/realesrgan-gui/master/macos-build-script.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5896 100 5896 0 0 5941 0 --:--:-- --:--:-- --:--:-- 5937
bash: line 4: syntax error near unexpected token else' bash: line 4: else'

遇到一樣的問題,也是在M1 MacOS上。

% curl -L https://raw.githubusercontent.com/TransparentLC/realesrgan-gui/master/macos-build-script.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5896  100  5896    0     0   8148      0 --:--:-- --:--:-- --:--:--  8143
bash: line 4: syntax error near unexpected token `else'
bash: line 4: `else'

遇到一樣的問題,也是在M1 MacOS上。

% curl -L https://raw.githubusercontent.com/TransparentLC/realesrgan-gui/master/macos-build-script.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5896  100  5896    0     0   8148      0 --:--:-- --:--:-- --:--:--  8143
bash: line 4: syntax error near unexpected token `else'
bash: line 4: `else'
rcl@Air Build % curl -L https://raw.githubusercontent.com/TransparentLC/realesrgan-gui/master/macos-build-script.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5896  100  5896    0     0   5667      0  0:00:01  0:00:01 --:--:--  5669
bash: line 4: syntax error near unexpected token `else'
bash: line 4: `else'

我不怎麼懂bash,但是自己摸一摸找到幾個暫時解方:

  1. 第四行 mirror_head="https://mirror.ghproxy.com/" 最後一條斜線去掉就能正常運行,但是mirror網域就不能用了,只能選no;
  2. 我這裡 MacOS 上還沒建立 venv 之前是不能用 pip 安裝任何 library 的,嘗試做 pip3 install virtualenv 時會跳出以下 error:
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:
    
    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz
    
    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with
    
    brew install pipx
    
    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.
    
    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.
    
    Read more about this behavior here: <https://peps.python.org/pep-0668/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.

我的解決方式是用 homebrew 事先安裝 virtualenv ,還是會跳出 error 但是後續步驟能正常進行;

以上暫時處理後 macos-build-script.sh 就能正常進行,程式也正確出現在 Download 資料夾裡了;但是結果跟直接從 release 下載的版本一樣,運行沒有反應。

有需要其他有關 M1 資訊或是 log 可以再告訴我,我可以幫忙測試。

倒推一個版本測試 Automated build 20240131-130138 M1 上可以正常使用。

https://github.com/TransparentLC/realesrgan-gui/compare/1071146fc4cdc4ef66ebe1037912a215473ad6e1..d662c7fad3c7596033cac2e852813a541068e2e8

这两个版本之间和操作系统有关的更改只有只会在 Windows 下生效的任务栏进度条。

如果不打包而是从源代码直接运行的话会有什么提示吗?

% ./venv/bin/python3 main.py
Traceback (most recent call last):
  File "/Users/user/Downloads/build/realesrgan-gui/main.py", line 21, in <module>
    import tkinter as tk
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'

這樣嗎?

python - ModuleNotFoundError: No module named '_tkinter' on macOS - Stack Overflow

Google 搜索了一下找到了这个,也许需要 brew install python-tk

安裝了,現在變這樣:

% ./venv/bin/python3 main.py 
/Users/user/Downloads/build/realesrgan-gui/main.py:721: DeprecationWarning: 'locale.getdefaultlocale' is deprecated and slated for removal in Python 3.15. Use setlocale(), getencoding() and getlocale() instead.
  'AppLanguage': locale.getdefaultlocale()[0],
Traceback (most recent call last):
  File "/Users/user/Downloads/build/realesrgan-gui/main.py", line 768, in <module>
    config, models = init_config_and_model_paths()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Downloads/build/realesrgan-gui/main.py", line 700, in init_config_and_model_paths
    config = configparser.ConfigParser({
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 625, in __init__
    self._read_defaults(defaults)
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 1202, in _read_defaults
    self.read_dict({self.default_section: defaults})
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 741, in read_dict
    self.set(section, key, value)
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 1183, in set
    self._validate_value_types(option=option, value=value)
  File "/opt/homebrew/Cellar/python@3.12/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 1168, in _validate_value_types
    raise TypeError("option values must be strings")
TypeError: option values must be strings

在 Python REPL 中执行以下代码的输出是什么?

import locale
locale.getdefaultlocale()

Windows 下的输出的类似于 ('zh_CN', 'cp936')

realesrgan-gui/main.py

Lines 700 to 722 in d662c7f

config = configparser.ConfigParser({
'Upscaler': '',
'ModelDir': '',
'ResizeMode': int(param.ResizeMode.RATIO),
'ResizeRatio': 4,
'ResizeWidth': 1024,
'ResizeHeight': 1024,
'ResizeLongestSide': 1024,
'ResizeShortestSide': 1024,
'Model': '',
'DownsampleIndex': 0,
'GPUID': -1,
'TileSizeIndex': 0,
'LossyQuality': 80,
'UseWebP': False,
'UseTTA': False,
'OptimizeGIF': False,
'LossyMode': False,
'IgnoreError': False,
'Preupscale': False,
'CustomCommand': '',
'AppLanguage': locale.getdefaultlocale()[0],
})

如果 AppLanguage 最后是 None 的话应该就会出现 TypeError: option values must be strings……

% ./venv/bin/python3        
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
<stdin>:1: DeprecationWarning: 'locale.getdefaultlocale' is deprecated and slated for removal in Python 3.15. Use setlocale(), getencoding() and getlocale() instead.
(None, 'UTF-8')

好像確實是None,哈哈

所以剩下的问题就是在 macOS 下怎么获得当前使用的语言标识了,在 Linux 下这个也会返回 ('zh_CN', 'UTF-8') 的。

我使用conda,在error: externally-managed-environment...的错误后,手动安装了requirements.txt中的依赖后可以正常运行