Python 3.13中从types模块导入freeze时出现ImportError问题求助
Python 3.13中从types模块导入freeze时出现ImportError问题求助
大家好,我最近在测试Python 3.13的新特性时碰到了个棘手的问题,想请各位大佬帮忙分析下:
首先我用conda创建了一个Python 3.13的虚拟环境,执行的命令是:
conda create --name base_313 python=3.13 -y conda activate base_313 code .
接着我写了一段测试代码,想试试Python 3.13新增的types.freeze功能来冻结类,代码如下:
from types import freeze class k: AGE = 42 NAME = "Zoubida" freeze(k) if __name__ == "__main__": print(k.AGE) # 预期输出42 try: k.AGE = 84 # 尝试修改类属性,应该触发异常 except TypeError as e: print(e)
结果运行代码直接炸了,报了ImportError,具体错误信息如下:
Exception has occurred: ImportError cannot import name 'freeze' from 'types' (c:\Users\phili\anaconda3\envs\base_313\Lib\types.py) File "C:\Users\phili\OneDrive\Documents\Tmp\const\main.py", line 24, in from types import freeze ImportError: cannot import name 'freeze' from 'types' (c:\Users\phili\anaconda3\envs\base_313\Lib\types.py)
我的conda版本是24.5.0:
conda --version conda 24.5.0
我特意查了Python 3.13的官方文档,types.freeze明明是这个版本新增的特性啊,怎么会导不进来呢?有没有朋友遇到过类似的情况,或者知道问题出在哪、该怎么解决吗?
备注:内容来源于stack exchange,提问作者40tude
相关产品推荐
相关产品推荐

