AWS p2 instance setup - Error Lesson 1 - ModuleNotFoundError: No module named 'cv2'

Hello everyone,
I am using Amazon p2 instance for the lessons. I have installed Anaconda 3.5 version that was suggested by Jeremy. Is there any setup required from software packages perspective ?

When I run the Lesson 1 Jupyter notebook, I get the below error. I am assuming, I will get more, unless I have full setup.

Command in Jupyter Notebook

        # This file contains all the main external libs we'll use
        from fastai.imports import *

Error :

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-2f3a3d7866ce> in <module>()
      1 # This file contains all the main external libs we'll use
----> 2 from fastai.imports import *

~/courses/fastai/courses/dl1/fastai/imports.py in <module>()
      1 from IPython.lib.deepreload import reload as dreload
----> 2 import PIL, os, numpy as np, math, collections, cv2, threading, json, bcolz, random, scipy
      3 import random, pandas as pd, pickle, sys, itertools, string, sys, re, datetime
      4 import seaborn as sns, matplotlib
      5 from abc import abstractmethod

ModuleNotFoundError: No module named 'cv2'

Should I install opencv ? I tried pip install opencv-python and it gave me another error. So I removed it.
Any suggestions ?

1 Like

if you installed latest anaconda3 version in aws box you will have python 3.6 by default.
Then you can do ‘pip install opencv-python’ to solve cv2 module not available error.

1 Like

Thanks, but I tried installing that in the past. I tried it again, but I get the below error.

ImportError                               Traceback (most recent call last)
<ipython-input-3-2f3a3d7866ce> in <module>()
      1 # This file contains all the main external libs we'll use
----> 2 from fastai.imports import *

~/courses/fastai/courses/dl1/fastai/imports.py in <module>()
      1 from IPython.lib.deepreload import reload as dreload
----> 2 import PIL, os, numpy as np, math, collections, cv2, threading, json, bcolz, random, scipy
      3 import random, pandas as pd, pickle, sys, itertools, string, sys, re, datetime
      4 import seaborn as sns, matplotlib
      5 from abc import abstractmethod

~/anaconda3/lib/python3.6/site-packages/cv2/__init__.py in <module>()
      7 
      8 # make IDE's (PyCharm) autocompletion happy
----> 9 from .cv2 import *
     10 
     11 # wildcard import above does not import "private" variables like __version__

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

Exactly the same issue I’m having. I thought it was a Windows thing but apparently not. I installed cv2 and some other missing libs only to find there was an unresolvable conflict in lib versions. I’ve restored my system and will try again. Perhaps I’ll have better luck a 2nd, 3rd time.

@bsalita, I have just found the solution. There is an OS level dependency that’s why we are getting this issue.

You should get the minimal debian dependencies for anaconda by running the command : apt-get install libsm6 libxrender1 libfontconfig1

6 Likes

Thank you @satheesh !
I met the same problem and your solution worked for me. I just added sudo in front of your command as follows :
sudo apt-get install libsm6 libxrender1 libfontconfig1

3 Likes

Great @pierreguillou, happy to hear !

@satheesh I have executed all the code in the discussion, I’m running on linux, but there’s still with the problem of “No module name ‘cv2’” on my jupyter notebook.

@chingjunehao for folks to be able to help you, you’ll need to provide the information requested here: http://wiki.fast.ai/index.php/How_to_ask_for_Help

@chingjunehao If you have tried with this commandsudo apt-get install libsm6 libxrender1 libfontconfig1 and pip install opencv-python and still have issues. I recommend setting up the environment as given by Jermey.

From the Github URL or in the jupyter notebook, you will find the environment.yml file at > courses/fastai/environment.yml

Go to bash and execute the below to install all dependencies using these two commands.
conda env create -f ~/downloads/environment.yml
Activate fastai
Now, it should have the dependencies installed and it should work. Exit and re-login to reflect the changes. No need to restart.
It should technically work…try and let me know.

Okay, thanks for reminding!

I have tried with sudo apt-get install libsm6 libxrender1 libfontconfig1 and pip install opencv-python command, but still have issues of “No module name cv2” on my jupyter notebook.

Then, I tried the command of
conda env create -f ~/fastai/environment.yml
source activate fastai
after I ssh to the aws p2 instances and activate the env, there’s still with the issue of

Notebook Validation failed: {u'model_id': u'e126fec017aa43a391f342328c05b6df', u'version_minor': 0, u'version_major': 2} is not valid under any of the given schemas:
{
 "model_id": "e126fec017aa43a391f342328c05b6df", 
 "version_minor": 0, 
 "version_major": 2
}

and the same module problem…

ImportError                               Traceback (most recent call last)
<ipython-input-1-2f3a3d7866ce> in <module>()
      1 # This file contains all the main external libs we'll use
----> 2 from fastai.imports import *

/home/ubuntu/fastai/courses/dl1/fastai/imports.py in <module>()
      1 from IPython.lib.deepreload import reload as dreload
----> 2 import PIL, os, numpy as np, math, collections, cv2, threading, json, bcolz, random, scipy
      3 import random, pandas as pd, pickle, sys, itertools, string, sys, re, datetime, time
      4 import seaborn as sns, matplotlib
      5 from abc import abstractmethod

ImportError: No module named cv2

@jeremy @satheesh Thanks for the help, the problem of cv2 module is solved.
But Still don’t understand the error of notebook validation error:

Notebook Validation failed: {u'model_id': u'e126fec017aa43a391f342328c05b6df', u'version_minor': 0, u'version_major': 2} is not valid under any of the given schemas:
{
 "model_id": "e126fec017aa43a391f342328c05b6df", 
 "version_minor": 0, 
 "version_major": 2
}

But after fixing those module problem, still have a problem of syntax error:

That means you’re not using python 3.6.

I suggest you use crestle if possible, since it’s all set up and ready to go!

@jeremy okay! thanks!