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

构建并安装Python wheel包后导入出现ModuleNotFoundError的问题

问题:Wheel包安装成功但导入失败(ModuleNotFoundError)

我把完整Python项目打包成wheel文件,按网上步骤构建并安装成功,但在同一环境中导入时出现ModuleNotFoundError。操作及报错信息如下:

(sancus) C:\Users\XXXX\Downloads\sancus-master\sancus-master\sancus\dist>pip install sancus_extraction-0.0.1-py3-none-any.whl
Processing c:\users\XXXX\downloads\sancus-master\sancus-master\sancus\dist\sancus_extraction-0.0.1-py3-none-any.whl
Installing collected packages: sancus-extraction
Successfully installed sancus-extraction-0.0.1

(sancus) C:\Users\XXXX\Downloads\sancus-master\sancus-master\sancus\dist>python
Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import sancus_extraction
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sancus_extraction'
>>>
解决方法
  • 重新激活conda环境:命令行前缀虽显示(sancus),但Python提示环境未激活。重新执行激活命令后再尝试导入:

    conda activate sancus
    python
    >>> import sancus_extraction
    
  • 核对模块实际导入名称:wheel包名称sancus-extraction不一定等于导入名称。可以:

    1. 执行pip show sancus-extraction查看包的安装路径
    2. 进入该路径,查看里面的文件夹/模块文件名,比如如果是sancus文件夹,导入命令应为import sancus
  • 检查打包配置文件:确认setup.py或pyproject.toml中packages参数是否正确指向要打包的模块,示例:

    setup(
        name="sancus-extraction",
        packages=["sancus_extraction"],  # 需与实际模块名一致
        # 其他配置项...
    )
    
  • 验证pip与Python环境一致性:执行where python和where pip(Windows),或which python和which pip(Linux/macOS),确认两者路径都属于sancus环境,避免pip安装到其他环境而Python调用的是另一个解释器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 04:39:34