解決python linebot "cannot import name 'Mapping' from 'collections'"問題

slash

解決import linebot的版本問題

問題描述

在使用網上基於flask的linebot範例時產生一下報錯:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Traceback (most recent call last):
File "C:\Users\User\Desktop\line-bot-tutorial-master\main.py", line 3, in <module>
from linebot import (
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\linebot\__init__.py", line 21, in <module>
from .api import ( # noqa
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\linebot\api.py", line 21, in <module>
from .http_client import HttpClient, RequestsHttpClient
dule>
import requests
le>
import urllib3
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 29, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 3, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\wait.py", line 1, in <modul from .selectors import (
<module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Users\User\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)

問題解決

爬了億下文,問題就出在linebot這個包裡的urllib3requesrs兩個模塊的版本問題
使用pip指令將urllib3requests移除後
先重新安裝urllib3到1.26.7版,再重新安裝requests到2.26版即可
command:

1
2
3
4
pip uninstall urllib3
pip uninstall requests
pip install urllib3==1.26.7
pip install requests==2.26

  • 標題: 解決python linebot "cannot import name 'Mapping' from 'collections'"問題
  • 作者: slash
  • 撰寫于: 2022-07-28 05:06:40
  • 更新于: 2022-11-08 05:17:07
  • 連結: https://slasholy.tw/2022/07/28/linebotimporterror/
  • 版權宣告: 本作品采用 CC BY-NC-SA 4.0 进行许可。
此頁目錄
解決python linebot "cannot import name 'Mapping' from 'collections'"問題