当前位置:AIGC资讯 > AIGC > 正文

Stable Diffusion 运行报错 TypeError: unsupported operand type(s) for |: ‘type‘ and ‘type‘

MacOS 上使用 python 3.8 版本安装运行 Stable Diffusion 时,有如下报错

Error loading script: lora_script.py
Traceback (most recent call last):
  File "/Users/admin/diy/stable-diffusion-webui/modules/scripts.py", line 256, in load_scripts
    script_module = script_loading.load_module(scriptfile.path)
  File "/Users/admin/diy/stable-diffusion-webui/modules/script_loading.py", line 11, in load_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/admin/diy/stable-diffusion-webui/extensions-builtin/Lora/scripts/lora_script.py", line 4, in <module>
    import lora
  File "/Users/admin/diy/stable-diffusion-webui/extensions-builtin/Lora/lora.py", line 238, in <module>
    def lora_apply_weights(self: torch.nn.Conv2d | torch.nn.Linear | torch.nn.MultiheadAttention):
TypeError: unsupported operand type(s) for |: 'type' and 'type'

这是因为之前老版本的 python 3.8 的兼容问题。

解决办法:

1. 方法一:升级 python 版本至 3.9+

2. 方法二:在 `lora.py` 文件中增加代码:from __future__ import annotations:

from __future__ import annotations
import glob
import os
import re
import torch

from modules import shared, devices, sd_models, errors

Problem solved~

更新时间 2023-11-22