ModuleNotFoundError: No module named 'fastai'

Okay, I tried this running pretty much letter for letter until I got this in step 7: ‘jupyter’ is not recognized as an internal or external command, operable program or batch file.

Not sure how to fix that.

I had this error message whilst running the code from a JupyterLab notebook. Turns out I just had to manually add the “fastai” kernel to the virtual environment created for the course (fastai). This stack overflow answer worked for me:

https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook

After activating your fastai environment, simply run this command:
python -m ipykernel install --user --name myenv --display-name “Python (myenv)”

I am using the standard Paperspace Notebook and everything works fine
When I restart the notebook I get the error in Jupyter:

from fastai.imports import *
ModuleNotFoundError: No module named 'fastai'

If I try to activate fastai from the terminal

source activate fastai 

I get

/bin/sh: 14: source: not found

I have read and tried many things so now I hope for a condensed answer.

4 Likes

In each .ipynb project you must add before importing fastai:

import sys
sys.path.append ('../../')
from fastai.imports import *

This way you can import files from other folders, in this case higher folders.

I hope I help you, regards

2 Likes

Hi,
I struggled a lot with installing this package, and it didn’t help that I’m a total noob when it comes to navigating in the command line. Anyway, after trying out a ton of different approaches (and learning a lot on the way), I thought I’d post what eventually solved my problems.

I am using Windows 10. I started out with Anaconda and git installed, and followed Jeremy’s instructions
cd C:\Users\[USERNAME]\Documents\GitHub (or wherever you have your git repo’s)
git clone https://github.com/fastai/fastai
cd fastai
conda create -n fastai python=3.6 anaconda
activate fastai
conda env update

ERROR

Command “python setup.py egg_info” failed with error code 1 in
C:\Users\ [USERNAME]\AppData\Local\Temp\pip- install-6pcncszt\shapely
CondaValueError: pip returned an error

Sources told me this error was caused by pip not being up to date, so I activated the new environment (“fastai”) and upgraded pip

TRY:
(still in the fastai-environment…)
python -m pip install --upgrade pip

This seemes to work. I now tried to run lecture 1 in jupyter notebook. I found out I could also run ipython in the command line to accesses the same python environment as the jupyter notebooks, which made the debugging somewhat easier.

deactivate
conda env update
activate fastai
jupyter notebook

IN JUPYTER NOTEBOOK:
run cell 1 (success)
run cell 2

ERROR:

ModuleNotFoundError: No module named ‘cv2’

I searched around and eventually found the bmatthewtaylor`s guide on Medium

TRY:
From bmatthewtaylor`s guide:

fixing this requires installing with pip and package opencv-python instead of cv2. Not obvious.
pip install opencv-python

ERROR:

ModuleNotFoundError: No module named ‘graphviz’

TRY:
pip install graphviz

ERROR:

ModuleNotFoundError: No module named ‘sklearn_pandas’

TRY:
pip install sklearn_pandas

ERROR:

ModuleNotFoundError: No module named ‘isoweek’

TRY:
pip install isoweek

ERROR:

No module named ‘pandas_summary’

TRY:
From bmatthewtaylor’s guide:

Turns out there are several packages requiring installation.

pip install pandas_summary
pip install torchtext
pip install feather-format
pip install jupyter_contrib_nbextensions
pip install plotnine
pip install docrepr
pip install awscli
pip install kaggle-cli
pip install pdpbox
pip install seaborn

jupyter notebook

IN JUPYTER NOTEBOOK:
run cell 1
run cell 2 ( success!! :smiley: )

Additional changes for Windows:
cell 3: PATH = "data\\bulldozers\\"
cell 4: !dir {PATH}

EDIT: Edited the formating
EDIT 2018-10-11: Corrected a mistake in the commands

1 Like

I followed the course setup for jupyter notebook on www.paperspace.com, but it was erroring out with the error "ModuleNotFoundError: No module named ‘fastai’ ".
To solve this, following code added in notebook (before line from fastai.imports import *)-

import sys
sys.path.append (’…/…/’)

Then I hit another error about directory ‘dogscats’ not found. I looked around and updated the path with following line and it worked. Hope it helps someone.

PATH = “…/…/…/data/dogscats/”

1 Like

Really not working after 1 full week of trial and error on a local machine (DELL M6700 Quadro M4000). Running as developer and running all commands, suggestions, links, etc, etc, etc and no luck. Clean install on clean windows 10 …

Same here. Using paperspace fast.ai notebook on Gradient.

  • First time it Just Works ™.
  • After restarting, I get this error.

Presumably setting the path will fix it, but why the change in behavior?
What is done on the first launch that is not done on the second, and how to fix that?

1 Like

Still, unsatisfying that we have to do this on reload/restart, but not the first time.

Ok, I see my “old card” is not supported… then I will have to upgrade notebook :frowning:

Agreed, same behaviour for me on PAPERSPACE GRADIENT (1/11/18) running FASTAI 0.7. The first time the notebook is opened the dl1 directory has fastai and data installed (as subdirectories of dl1). When the machine is stopped/restarted these subdirectories are gone.

Doing the sys.path.append is an incomplete work around. You then have to change the PATH string further down lesson 1 to find the data (managed to figure that out) and then the model has more problems when you get to the learning step (too complex for me).

I am concluding that there is some setup procedure or environment setting not being restored when the machine is stopped/restarted. Very annoying when you are struggling with “only just enough skills”. JB

I second this. Perhaps this should be mentioned as a possible fix on the Windows setup threat? However, it lead me to a new problem, that is

C:\Users\username\fastai\fastai\courses\dl1\fastai\imports.py in ()
1 from IPython.lib.deepreload import reload as dreload
----> 2 import PIL, os, numpy as np, math, collections, threading, json, bcolz, random, scipy, cv2
3 import pandas as pd, pickle, sys, itertools, string, sys, re, datetime, time, shutil, copy
4 import seaborn as sns, matplotlib
5 import IPython, graphviz, sklearn_pandas, sklearn, warnings, pdb

ModuleNotFoundError: No module named ‘bcolz’

Do I understand correctly that Python is trying to download an external module called “bcolz”, but can’t find it? Does anyone have an idea what the problem could be?

Follow this link for a solution:

1 Like

The above worked to fix the module error.
But to fix the dogscats error I had to use this:

PATH = “/data/dogscats/”

(using PaperSpace Gradient)

I hope this helps someone else using custom environments with condas getting the “ModuleNotFoundError: No module named ‘fastai’”.

conda create -n myenv
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

that should now add it to the jupyter kernels.

In Jupyter:
Kernel -> Change Kernel -> Python(myenv)

EDIT: to have jupyter load the new condas environment by default so you don’t have to change the kernel every time in a notebook, start jupyter with “–ExecutePreprocessor.kernel_name=myenv”

EX:

"jupyter notebook --ExecutePreprocessor.kernel_name=myenv"

Thanks, I can choose the kernel in jupyter but still gets lots of import errors. You got it working?

I’m also having problems with paperspace gradient. After a restart, fast.ai imports are no longer working and there are things missing from the PATH (like Graphviz when trying to plot the tree). Has anybody found a good workaround for these problems? My linux skills are not good enough for me to realise if graphviz no longer is installed, or if it’s just missing from the PATH

Hey,

Sorry for the late response, I’ve been trying to figure out the cleanest method for running this in their own environments and finally think I got it.

I will make a blog post on creating a server from scratch. In the mean time, were you able to get setup and going?

For the issues on the paperspace gradient notebooks, it seems that the symlinks are getting removed when the notebook is restarted.

If add the symlinks to the course directory you are working within, it should fix any problems for notebooks / missing dependencies within that course directory.

from one of my notebooks in courses/dl1 i added:

!ln -s ../../fastai fastai
!ln -s ../../data data

the module not found errors don’t occur now.

1 Like

actually, looking into it more you could just do git checkout . from the /notebooks directory (the default starting location if you open a new terminal) and that should clear up the missing directory issues as well as many others :slight_smile: