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

安装InstagramAPI后报错,重装Python仍遇ModuleNotFoundError等问题求助

解决InstagramAPI与Python3.10兼容及依赖冲突问题

一、用虚拟环境彻底隔离依赖

  • 创建并激活独立虚拟环境,避免全局包冲突:
    # 创建虚拟环境
    python -m venv ig_env
    # Windows系统激活
    ig_env\Scripts\activate
    # macOS/Linux系统激活
    source ig_env/bin/activate
    
  • 激活后操作的pip和Python均为虚拟环境内的版本,不会干扰全局环境。

二、修复AttributeError: module 'collections' has no attribute 'MutableMapping'

该错误因Python3.10+将MutableMapping从collections迁移至collections.abc,而部分依赖库仍使用旧导入路径,可通过以下两种方式解决:

方式1:添加临时兼容性代码

在你的项目主文件最顶部插入以下代码,提前完成路径映射:

import collections
try:
    collections.MutableMapping
except AttributeError:
    collections.MutableMapping = collections.abc.MutableMapping

方式2:修改依赖库源码

找到虚拟环境Lib/site-packages目录下报错的库文件,将from collections import MutableMapping替换为from collections.abc import MutableMapping。若为InstagramAPI自身代码问题,直接修改其对应源码文件即可。

三、安装兼容版本的依赖

  • 先安装适配Python3.10的urllib3版本:
    pip install urllib3==1.26.15
    
  • 安装GitHub最新适配分支的InstagramAPI(PyPI官方版本可能未适配3.10):
    pip install git+https://github.com/LevPasha/Instagram-API-python.git
    
  • 若需同时使用instabot,安装兼容3.10的版本:
    pip install instabot==0.117.0
    

四、验证运行

保持虚拟环境激活状态,运行你的项目程序。若仍有依赖问题,可通过pip list查看所有包版本,进一步排查冲突项。

内容的提问来源于stack exchange,提问作者Bartłomiej Czech

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 10:57:03