[GH-ISSUE #4] ImportError: cannot import name 'Mapping' from 'collections' #1

Closed
opened 2026-10-26 21:08:41 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @NickLucche on GitHub (Mar 11, 2024).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL/issues/4

Hey, thanks a lot for sharing this great accomplishment with the community!
I have just tried running the cli_chat on Python3.11 and I get ImportError: cannot import name 'Mapping' from 'collections' at https://github.com/deepseek-ai/DeepSeek-VL/blob/main/deepseek_vl/models/modeling_vlm.py#L21.
I believe this is due to attrdict being broken with python3.10+ https://stackoverflow.com/questions/72361026/how-can-i-get-attrdict-module-working-in-python.

Easiest thing would be to update Readme/requirements to specify >=python3.8, <3.10.

Originally created by @NickLucche on GitHub (Mar 11, 2024). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL/issues/4 Hey, thanks a lot for sharing this great accomplishment with the community! I have just tried running the `cli_chat` on Python3.11 and I get `ImportError: cannot import name 'Mapping' from 'collections'` at https://github.com/deepseek-ai/DeepSeek-VL/blob/main/deepseek_vl/models/modeling_vlm.py#L21. I believe this is due to attrdict being broken with python3.10+ https://stackoverflow.com/questions/72361026/how-can-i-get-attrdict-module-working-in-python. Easiest thing would be to update Readme/requirements to specify >=python3.8, <3.10.
bsakaguchi 2026-10-26 21:08:41 +00:00
Author
Owner

@Fodark commented on GitHub (Mar 11, 2024):

I solved it by patching collections before loading deepseek_vl

Something like:

# Monkey patch collections
import collections
import collections.abc
for type_name in collections.abc.__all__:
    setattr(collections, type_name, getattr(collections.abc, type_name))

from deepseek_vl.models import VLChatProcessor, MultiModalityCausalLM

if you want to stay on Python 3.10.

<!-- gh-comment-id:1988931879 --> @Fodark commented on GitHub (Mar 11, 2024): I solved it by patching collections before loading `deepseek_vl` Something like: ```python # Monkey patch collections import collections import collections.abc for type_name in collections.abc.__all__: setattr(collections, type_name, getattr(collections.abc, type_name)) from deepseek_vl.models import VLChatProcessor, MultiModalityCausalLM ``` if you want to stay on Python 3.10.
Author
Owner

@insightbuilder commented on GitHub (Mar 12, 2024):

I did a bit of hardway... went to each of the files in the lib folders and moded it...

  • aimachine/lib/python3.10/site-packages/attrdict/default.py
  • aimachine/lib/python3.10/site-packages/attrdict/merge.py
  • aimachine/lib/python3.10/site-packages/attrdict/mixins.py
  • aimachine/lib/python3.10/site-packages/attrdict/mapping.py

After doing it, came for posting the solution to find that, there is a smarter solution. Thanks to Fodark.

import collections.abc
for type_name in collections.abc.__all__:
    setattr(collections, type_name, getattr(collections.abc, type_name))
<!-- gh-comment-id:1991632432 --> @insightbuilder commented on GitHub (Mar 12, 2024): I did a bit of hardway... went to each of the files in the lib folders and moded it... - aimachine/lib/python3.10/site-packages/attrdict/default.py - aimachine/lib/python3.10/site-packages/attrdict/merge.py - aimachine/lib/python3.10/site-packages/attrdict/mixins.py - aimachine/lib/python3.10/site-packages/attrdict/mapping.py After doing it, came for posting the solution to find that, there is a smarter solution. Thanks to Fodark. > ```python > import collections.abc > for type_name in collections.abc.__all__: > setattr(collections, type_name, getattr(collections.abc, type_name)) > ```
Author
Owner

@Fodark commented on GitHub (Mar 14, 2024):

Fixed in #21

<!-- gh-comment-id:1997868268 --> @Fodark commented on GitHub (Mar 14, 2024): Fixed in #21
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-VL#1
No description provided.