Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Error: cannot import name 'Mapping' from 'collections' #13395

Closed
dobrik4ever opened this issue Jun 23, 2022 · 2 comments
Closed

Import Error: cannot import name 'Mapping' from 'collections' #13395

dobrik4ever opened this issue Jun 23, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@dobrik4ever
Copy link

dobrik4ever commented Jun 23, 2022

🐛 Bug

On python 3.10.4 got a following error:

To Reproduce

Python 3.10.4 | packaged by conda-forge | (main, Mar 30 2022, 08:38:02) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytorch_lightning as pl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\__init__.py", line 53, in <module>    
    from pytorch_lightning.core import LightningModule, data_loader
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\core\__init__.py", line 339, in <module>
    from pytorch_lightning.core.decorators import data_loader
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\core\decorators.py", line 6, in <module>
    from pytorch_lightning.core.lightning import LightningModule
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\core\lightning.py", line 19, in <module>
    from pytorch_lightning.core.hooks import ModelHooks
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\core\hooks.py", line 7, in <module>   
    from pytorch_lightning.utilities import move_data_to_device, NATIVE_AMP_AVALAIBLE
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\utilities\__init__.py", line 7, in <module>
    from pytorch_lightning.utilities.apply_func import move_data_to_device
  File "C:\ProgramData\Anaconda3\envs\dl\lib\site-packages\pytorch_lightning\utilities\apply_func.py", line 2, in <module>
    from collections import Mapping, Sequence
ImportError: cannot import name 'Mapping' from 'collections' (C:\ProgramData\Anaconda3\envs\dl\lib\collections\__init__.py)

Expected behavior

When importing pl the ImportError raised

  • PyTorch Lightning Version: 0.8.5
  • Python version: 3.10.4
  • OS: Windows 10
@dobrik4ever dobrik4ever added the needs triage Waiting to be triaged by maintainers label Jun 23, 2022
@dobrik4ever dobrik4ever changed the title Import Error: Import Error: cannot import name 'Mapping' from 'collections' Jun 23, 2022
@akihironitta akihironitta added bug Something isn't working and removed needs triage Waiting to be triaged by maintainers labels Jun 23, 2022
@akihironitta
Copy link
Contributor

@dobrik4ever The version of PyTorch Lightning you're using seems very old. Would you mind updating to the stable release by running pip install pytorch-lightning -U and trying it again? Let me know if it resolves this issue.

Please note that, as of now, we are not testing PyTorch Lightning with Python 3.10, but if the problem still persists, it'll be addressed via #9980.

@awaelchli
Copy link
Contributor

We no longer have this import statement in the code base. It was changed in #2746 so this should be resolved. As @akihironitta said, the solution is to update lightning to a recent version or to downgrade Python to an older version. I don't see any direct relationship to Python 3.10 incompatibility otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants