Python thinkdsp包安装后无法导入decorate的问题求助
问题:thinkdsp导入decorate失败及版本差异问题
操作流程
- 启动Windows 10的PowerShell
- 创建项目文件夹
myDSP - 检查已安装Python版本(3.10、3.8、3.7)
- 进入项目目录
- 基于Python3.8创建虚拟环境
myenv - 激活虚拟环境
- 执行
pip install thinkx安装包 - 创建
script.py并写入代码:
from thinkdsp import SinSignal from thinkdsp import decorate
运行错误
C:\Users\WORKINGSTATION\myDSP\myenv\lib\site-packages\thinkdsp.py:32: UserWarning: Can't import Audio from IPython.display; Wave.make_audio() will not work. warnings.warn("Can't import Audio from IPython.display; " Traceback (most recent call last): File ".\script.py", line 2, in <module> from thinkdsp import decorate ImportError: cannot import name 'decorate' from 'thinkdsp' (C:\Users\WORKINGSTATION\myDSP\myenv\lib\site-packages\thinkdsp.py)
问题原因
你执行的pip install thinkx安装的是错误的包——PyPI上的thinkx并非官方ThinkDSP库,而是一个第三方的不完整版本,和GitHub仓库的官方代码差异极大,缺失了decorate等核心方法。官方ThinkDSP在PyPI上的正确包名是thinkdsp。
解决步骤
- 卸载错误安装的包:
pip uninstall thinkx -y
- 安装官方的ThinkDSP包:
pip install thinkdsp
- (可选)如果需要和GitHub仓库完全一致的最新版本,直接从源码安装:
pip install git+https://github.com/AllenDowney/ThinkDSP.git
- 重新运行
script.py即可正常导入decorate方法。
内容的提问来源于stack exchange,提问作者Marco Moldenhauer
相关产品推荐
相关产品推荐

