question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot import name 'PY3' from 'torch._six' on fresh install of bolts

See original GitHub issue

🐛 Bug

Fresh install of pytorch-lightning and pytorch-lightning bolts leads to error cannot import name 'PY3' from 'torch._six'

Looks like it was renamed to PY37 in torch._six. I changed all references to PY3 to PY37 inside pl_bolts/datasets/imagenet_dataset.py and the problem resolved.

Traceback (most recent call last):
  File "debugtuner.py", line 4, in <module>
    from pl_bolts.datamodules import MNISTDataModule
  File "/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/pl_bolts/__init__.py", line 47, in <module>
    from pl_bolts import callbacks, datamodules, datasets, losses, metrics, models, optimizers, transforms, utils
  File "/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/pl_bolts/datamodules/__init__.py", line 2, in <module>
    from pl_bolts.datamodules.binary_mnist_datamodule import BinaryMNISTDataModule
  File "/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/pl_bolts/datamodules/binary_mnist_datamodule.py", line 4, in <module>
    from pl_bolts.datasets import BinaryMNIST
  File "/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/pl_bolts/datasets/__init__.py", line 11, in <module>
    from pl_bolts.datasets.imagenet_dataset import extract_archive, parse_devkit_archive, UnlabeledImagenet
  File "/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/pl_bolts/datasets/imagenet_dataset.py", line 12, in <module>
    from torch._six import PY3
ImportError: cannot import name 'PY3' from 'torch._six' (/home/davina/miniconda3/envs/ap/lib/python3.8/site-packages/torch/_six.py)

Code sample

from pl_bolts.datamodules import MNISTDataModule

Expected behavior

the package should run with no error.

Environment

  • PyTorch Version (e.g., 1.0): 1.8
  • OS (e.g., Linux): MacOs
  • How you installed PyTorch (conda, pip, source): conda
  • Build command you used (if compiling from source): pip install
  • Python version: 3.8
  • CUDA/cuDNN version: 10.1
  • GPU models and configuration: 4 nvidia gpus
  • Any other relevant information:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davzamancommented, Mar 8, 2021

I created a new env and instead of pip install pytorch-lightning-bolts I ran what you suggested and tried importing the MNISTDataModule and it did not produce errors.

0reactions
Bordacommented, Mar 8, 2021

so it was fixed with #579

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: cannot import name 'PY3' from 'torch._six'
For this question, the reason is that your 'torchvision' and 'pytorch' version, ... the new version pip install --upgrade torch torchvision.
Read more >
ImportError: cannot import name 'PY3' from 'torch._six ... - GitHub
The error comes from from torchvision import datasets therefore unrelated to this project.
Read more >
Importerror: Cannot Import Name 'Py3' From 'Torch.Six'
I used the command conda install pytorch torchvision c pytorch from the official 4 import random \anaconda3\envs\pytorch\lib\sitepackages\d2l\torch.
Read more >
pytorch lightning import error - You.com | The AI Search ...
Pytorch lightning cannot be successfully imported after a fresh conda install due to a mismatch between tensorboard and distutils versions. I tried going...
Read more >
Error when using the napari-cellpose plugin - Image.sc Forum
Hello, I try to get cellpose running within napari but when clicking on either 'compute diameter from image' or 'run segmentation' I get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found