ModuleNotFoundError: No module named 'dataclasses'

While running below imports , I am getting the mentioned error - ModuleNotFoundError: No module named ‘dataclasses’

from fastai.imports import *
from fastai.structured import *

from pandas_summary import DataFrameSummary
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from IPython.display import display

from sklearn import metrics

I am using the fastai-cpu env in windows 10 , kind help to resolve the issue would be appreciated.

1 Like

Dataclasses were introduced with Python 3.7.

Are you using the correct Python version?

I am using Python 3.6.6 , any idea how to resolve it ?

1 Like

I resolved it using pip install dataclasses, but now am facing a different issue.

Any idea?

2 Likes

dataclasses are a new feature of python 3.7 (not 3.6 as stated in another post). It is possible to install backports on older versions but fastai v1 requires python 3.7 and I don’t know if dataclasses alone will fix all issues. better create a conda env with 3.7 installed before installing fastai.
conda create -n fastaiv1py37 -c anaconda python=3.7

EDIT: This was wrong information, as visible from the setup.py for the library only dataclasses are required, so 3.6 with it installed should work fine!!

1 Like

and by the way: The error means you probably installed v1, but the ML course uses the old version of fastai (now called 0.7) which is not fully compatible, so you should install that version, not v1. otherwise the notebooks will not work correctly. Look for several discussions of that on the forum for details.

1 Like

Can you kindly guide to a correct post for the machine learning env set up ?

I have updated my conda python version to 3.7.0 but when I am running the conda env update -f environment-cpu.yml , the python version for the fastai-cpu version is getting changed to 3.6.6.

Kindly guide.

1 Like

3.6.6 should not be much of a problem as this is what the course is designed for.

As @marcmuc mentions, it seems as if you have the fastai v1 version installed.

Do you get the error in some code of yours, or when using one of the notebooks from courses/ml1/ (or in general a notebook in this very directory)?
I ask as in this directory is an explicit link to the old version of the library. This should prevent the error.

I am running courses/ml1/1st lesson notebook and getting error while running the imports that is present in the notebook. Can you please provide me the steps to install the correct version for ml course.

Hm. This is weird.

Aber creating the environment did you do anything like conda install fastai or pip install fastai?

Can you confirm that courses/ml1/fstai is a proper link to the old fastai version?

I only started yesterday and once I had the CPU only environment in place things were working as expected.

try starting with a clean conda env or pip and install fastai via pip install fastai==0.7.0
you may have to install jupyter, matplotlib, numpy and pandas manually too. If you then encounter errors while using the library just install whatever it says it cannot find. Not a great approach but should get you there. And do use an older pytorch version, not 1.0.0-nightly. And use the cpu version of pytorch.

and this thread is starting to become a mess :-(. Please provide more info on what kind of OS, setup etc. youare actually working on otherwise helping is difficult.

After all I think all what was needed was

conda env create -n fastai -f environment-cpu.yml

OS - Windows 10
conda version : 4.5.11
conda-build version : 3.15.1
python version : 3.6.6

followed below mentioned steps -

  1. git clone https://github.com/fastai/fastai.git
  2. cd fastai
  3. conda env update -f environment-cpu.yml
  4. resolved few pip install error by installing from whl file
  5. activate fastai-cpu
  6. jupyter nbextension enable --py widgetsnbextension --sys-prefix
  7. cd courses\ml1
    del fastai
    mklink /d fastai …\fastai
    cd …

given the steps above.

What are you installing in step 4?

Why the relinking in step 4? The link must point to ../../old/fastai so you are using fastai 0.7 and not 1.0.

1 Like

yes, so as @aberres writes, you are definitely linking the wrong folder, so this is why you are using v1 of fastai and getting the dataclasses error and other problems. so remove those links and link the correct “old” folder. if that does not help then within that environment do the pip install of 0.7.0 like stated above.

@stas has just opened a new thread for v0.7 installation issues (which are probably plenty, because old posts all make you do stuff that doesn‘t work now anymore, such as your mklink stuff above). This explanation should get you there:

Thank you @marcmuc & @aberres for the help.

No I have resolved the error for dataclasses pointing to old/fastai folder , however now I am getting below mentioned error.

ModuleNotFoundError: No module named ‘bcolz’

in the fastai-cpu env did the installation of bcolz (conda install -c anaconda bcolz) but still getting the same error.

Any idea about this one ?

Not sure, but always search the forums first. You are not alone with this problem, look for solutions here :slight_smile::

2 Likes