You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SOAP服务运行失败:ModuleNotFoundError: spyne.util.six.moves模块缺失

解决Spyne中ModuleNotFoundError: No module named 'spyne.util.six.moves'问题

我编写了一段基于Spyne的SOAP服务代码,用于判断数字的奇偶性,运行时出现报错,提示ModuleNotFoundError: No module named 'spyne.util.six.moves',重新安装Spyne后问题仍未解决。

代码示例

from spyne import ServiceBase, Application, rpc, Integer, String
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server

class OddOrEvenService(ServiceBase):

    @rpc(Integer, _returns=String)
    def oddOrEven(self, num):
        if num % 2 == 0:
            return "even"
        else:
            return "odd"
 

application = Application([OddOrEvenService], 'my.soap.app',
        in_protocol=Soap11(),
        out_protocol=Soap11(),
    )

wsgi_app = WsgiApplication(application)
server = make_server('127.0.0.1', 7789, wsgi_app)

print ("listening to http://127.0.0.1:7789")
print ("wsdl is at: http://localhost:7789/?wsdl")

server.serve_forever()

报错信息

Traceback (most recent call last):
File "d:\Studii IT\Cursuri\First_SOAP_project.py", line 1, in <module>
from spyne import ServiceBase, Application, rpc, Integer, String
File"C:\Users\Enter83\AppData\Local\Programs\Python\Python312\Lib\site-packages\spyne\__init__.py", line 39, in <module>    
from spyne.evmgr import EventManager
File "C:\Users\Enter83\AppData\Local\Programs\Python\Python312\Lib\site-packages\spyne\evmgr.py", line 21, in <module>   
from spyne.util.oset import oset
File "C:\Users\Enter 83\AppData\Local\Programs\Python\Python312\Lib\site-packages\spyne\util\oset.py", line 3, in <module>
from spyne.util.six.moves.collections_abc import MutableSet
ModuleNotFoundError: No module named 'spyne.util.six.moves'

解决方案

  • 根本原因:Spyne稳定版与Python 3.12存在兼容性问题,spyne.util.six模块的导入结构未适配Python 3.12的环境。
  • 方案1:安装Spyne开发版
    官方稳定版暂未完全适配Python 3.12,可直接安装最新开发分支:
    pip install git+https://github.com/arskom/spyne.git
    
  • 方案2:降级Python版本
    将Python版本降至3.11或更低,再重新安装Spyne稳定版:
    pip install spyne
    
  • 方案3:手动修复导入(不推荐)
    先安装six库:
    pip install six
    
    找到Python环境中spyne/util/oset.py文件,将导入语句修改为:
    from six.moves.collections_abc import MutableSet
    

内容的提问来源于stack exchange,提问作者SPGA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 05:53:19