You need to enable JavaScript to run this app. 已安装customtkinter与darkdetect仍触发ModuleNotFoundError求助
优惠活动
大模型
产品
解决方案
定价
更多

已安装customtkinter与darkdetect仍触发ModuleNotFoundError求助

解决CustomTkinter导入的ModuleNotFoundError问题

先排查Python环境一致性

  • 打开终端,运行pip --version,记下显示的Python路径(比如/usr/bin/python3.10或C:\Python310\Scripts\pip.exe)
  • 再运行python --version,看路径是否和pip的一致。如果不一致,说明你用的Python解释器和安装模块的环境不匹配:
    • 若用的是虚拟环境,先激活对应的虚拟环境再运行脚本
    • 直接用对应路径的Python运行脚本,比如/usr/bin/python3.10 your_script.py
    • 或者用pip3代替pip安装模块,确保对应Python3

检查模块安装状态

  • 运行pip show customtkinter,如果没有输出,说明模块没装成功,执行:
    pip uninstall -y customtkinter darkdetect
    pip install customtkinter
    
    (CustomTkinter安装时会自动安装依赖darkdetect,无需手动单独安装)
  • 若显示已安装,确认安装路径是否在Python的模块搜索路径里:
    在Python交互环境运行:
    import sys
    print(sys.path)
    
    看pip show输出的Location路径是否在其中,不在的话可以手动添加:
    import sys
    sys.path.append("你的customtkinter安装路径")
    

关于手动下载的源码文件夹

  • 如果你把CustomTkinter源码文件夹放在项目里,确保脚本和该文件夹同级(比如脚本main.py和customtkinter文件夹都在项目根目录)
  • 如果脚本在子文件夹,在脚本开头添加:
    import sys
    import os
    # 把项目根目录加入Python搜索路径
    sys.path.append(os.path.dirname(os.path.abspath(__file__)))
    
  • 优先建议用pip安装官方包,手动放源码容易出现文件缺失、版本不兼容问题

IDE配置检查

  • 如果用PyCharm、VS Code等IDE,确认配置的Python解释器是安装了CustomTkinter的那个:
    • PyCharm:File → Settings → Project: xxx → Python Interpreter
    • VS Code:左下角状态栏点击Python版本,选择对应环境

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 03:21:30