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 'SklearnDataModule' from 'pl_bolts.datamodules'

See original GitHub issue

🐛 Bug

I cannot import a key module, even after a fresh install.

To Reproduce

Steps to reproduce the behavior:

Install package to fresh virtualenv and try import. Import fails. See code below.

This is on macOS Catalina Terminal with python 3.8.5

Code sample

$ python3 -m venv venv  
$ source venv/bin/activate 
(venv) $ pip install pytorch-lightning-bolts 
(venv) $ python
Python 3.8.5 (default, Jul 21 2020, 10:48:26) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from pl_bolts.datamodules import SklearnDataModule

Error 1: This fails with:

>>> from pl_bolts.datamodules import SklearnDataModule


/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/models/mnist_module.py:14: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/callbacks/variational.py:9: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/callbacks/vision/image_generation.py:9: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/datamodules/binary_mnist_datamodule.py:12: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/datamodules/cifar10_dataset.py:13: UserWarning: You want to use `Pillow` which is not installed yet, install it with `pip install Pillow`.
  warn('You want to use `Pillow` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/transforms/dataset_normalizations.py:5: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/datamodules/cifar10_datamodule.py:17: UserWarning: You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.
  warn('You want to use `torchvision` which is not installed yet,'  # pragma: no-cover
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'SklearnDataModule' from 'pl_bolts.datamodules' (/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/datamodules/__init__.py)

So I install torchvision (is it strictly necessary just for the SklearnModule?)

(venv) $ pip install torchvision 
(venv) $ python                 
>>> from pl_bolts.datamodules import SklearnDataModule

Error 2: This fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'SklearnDataModule' from 'pl_bolts.datamodules' (/Users/paczuskp/projects_gene/raan-lung-2020/code/py/venv/lib/python3.8/site-packages/pl_bolts/datamodules/__init__.py)

Expected behavior

Import loads with no error

Environment

(venv) $ pip freeze
absl-py==0.11.0
cachetools==4.1.1
certifi==2020.11.8
chardet==3.0.4
dataclasses==0.6
fsspec==0.8.4
future==0.18.2
google-auth==1.23.0
google-auth-oauthlib==0.4.2
grpcio==1.33.2
idna==2.10
Markdown==3.3.3
numpy==1.19.4
oauthlib==3.1.0
Pillow==8.0.1
protobuf==3.14.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pytorch-lightning==1.0.7
pytorch-lightning-bolts==0.2.5
PyYAML==5.3.1
requests==2.25.0
requests-oauthlib==1.3.0
rsa==4.6
six==1.15.0
tensorboard==2.4.0
tensorboard-plugin-wit==1.7.0
torch==1.7.0
torchvision==0.8.1
tqdm==4.52.0
typing-extensions==3.7.4.3
urllib3==1.26.2
Werkzeug==1.0.1

Additional context

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
akihironittacommented, Nov 19, 2020

@pavopax :]

So I install torchvision (is it strictly necessary just for the SklearnModule?) Here, torchvision and Pillow need to be installed, which I do. But still get error

Actually, you don’t need either of them… You only need sklearn in your case. The current Bolts warns users of unavailable optional packages even when they actually don’t need them installed, which can be improved…

0reactions
plpxskcommented, Nov 19, 2020

Thanks, yes it works now. I upgraded package to the GitHub version and also installed scikit-learn, and issue is resolved.

Please close as you see fit. Cheers 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

lightning-bolts/sklearn_datamodule.py at master - GitHub
Cannot retrieve contributors at this time ... from pl_bolts.utils.stability import under_review ... from pl_bolts.datamodules import SklearnDataModule.
Read more >
pytorch-lightning-bolts - PyPI
The main goal of Bolts is to enable rapid model idea iteration. Example 1: Finetuning on data. from pl_bolts.models.self_supervised import SimCLR from pl_bolts...
Read more >
Lightning-Bolts Documentation
from pl_bolts.datamodules import SklearnDataModule ... Gradient descent over a batch of samples can not only benefit the ... a custom logged name.
Read more >
Unable to import pytorch_lightning on google colab
As said in Issue #6415 on Github, try installing from the GitHub. It worked for me.
Read more >
PyTorchLightning - Bountysource
Then I tested on the CIFAR10 DataModule and realized that I have a similiar issue on the standard code ... from pl_bolts.models.autoencoders import...
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