Fastai-cpu cv2 install issues on Linux

I’m migrating my project to a different server and ran into some problems while installing fastai for use without a GPU.

Anaconda installed,
fastai cloned from git,
conda env update -f environment-cpu.yml returns an error

Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-9a6red14/pyproj/

Then, when I try to do from fastai import structured I get the following errors:

ModuleNotFoundError: No module named 'cv2’

I pushed on and manually did pip install opencv-python and now from fastai import structured returns

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

I want out of the rabbit hole. I spit out the red pill and take the blue instead.

I guess you need to execute the following command to fix the issue.

apt update && apt install -y libsm6 libxext6

1 Like

I must add sudo to run your suggested command.
Then I get a slightly different error

from fastai import structured
[…]
from .cv2 import *
ImportError: libXrender.so.1: cannot open shared object file: No such file or directory

Edit: So then I try to fix that error with sudo apt-get install -y libxrender-dev
Then python gives the error:

raise ImportError(“Failed to import any qt binding”)
ImportError: Failed to import any qt binding

How come so many things suddenly not work?
I recently installed fastai on another linux machine with none of these problems.

Thats weird ! Can you please provide more details on what you are trying to achieve?
Are you trying to create a new conda environment with cpu version of fastai on a new server?
If yes can provide the OS Details and steps followed so far with error stack and instance/Hardware details?

I simply want to run my own prediction code on a different linux machine.

To answer your question; yes, new Linux machine, new conda environment with the cpu version of fastai.

I follow the steps to install for cpu

conda env update -f environment-cpu.yml

I just updated the OS; uname -a:
Linux username 4.15.0-1021-azure #21-Ubuntu SMP

1 Like

I am not sure about the cause of the problem. But , you can try the following :
Remove the existing conda environment created, if any using : conda env remove -n fastai-cpu
Create the environment using the following : conda env create -f environment-cpu.yml
Activate the Environment using conda activate fastai-cpu
P.S : Try to Use Dedicated SSH Client like putty/MobaXterm for running the command instead of Web Terminal.

Hope it helps!
~Gokkul

I removed and recreated the environemt.
As before, I get this error when running conda env create -f environment-cpu.yml

distutils.errors.CompileError: command 'gcc' failed with exit status 1

----------------------------------------

Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-a29hhew7/pyproj/

CondaValueError: pip returned an error

I cannot run conda activate fastai-cpu because

CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.

So instead I use source activate fastai-cpu and get the same original error when I try to do from fastai import structured:

ModuleNotFoundError: No module named ‘cv2’

(I’m using the dedicated SSH client from Bitwise)

Getting exact the same issue. First of all, I am trying to install fastai cpu environment on docker for windows. As a start image I am using continuumio/miniconda3 image. Then after cloning the fastai repo and running cd fastai && conda env update -f environment-cpu.yml I am getting installed env. However, simple command from fastai import conv_learner fails with next error:

from fastai import conv_learner
Traceback (most recent call last):
File “”, line 1, in
File “/home/fastai/fastai/conv_learner.py”, line 1, in
from .core import *
File “/home/fastai/fastai/core.py”, line 1, in
from .imports import *
File “/home/fastai/fastai/imports.py”, line 2, in
import PIL, os, numpy as np, math, collections, threading, json, bcolz, random, scipy, cv2
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/cv2/init.py”, line 3, in
from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

This can be solved out with apt install -y libsm6 libxext6 libxrender-dev , but still, the same command raises another error:

from fastai import conv_learner
Traceback (most recent call last):
File “”, line 1, in
File “/home/fastai/fastai/conv_learner.py”, line 1, in
from .core import *
File “/home/fastai/fastai/core.py”, line 1, in
from .imports import *
File “/home/fastai/fastai/imports.py”, line 4, in
import seaborn as sns, matplotlib
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/seaborn/init.py”, line 6, in
from .rcmod import *
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/seaborn/rcmod.py”, line 5, in
from . import palettes, _orig_rc_params
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/seaborn/palettes.py”, line 12, in
from .utils import desaturate, set_hls_values, get_color_cycle
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/seaborn/utils.py”, line 11, in
import matplotlib.pyplot as plt
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/pyplot.py”, line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/init.py”, line 62, in pylab_setup
[backend_name], 0)
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py”, line 15, in
from .backend_qt5 import (
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py”, line 19, in
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py”, line 20, in
import matplotlib.backends.qt_editor.formlayout as formlayout
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/qt_editor/formlayout.py”, line 54, in
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
File “/opt/conda/envs/fastai-cpu/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py”, line 158, in
raise ImportError(“Failed to import any qt binding”)
ImportError: Failed to import any qt binding

Though I have installed a couple of days earlier the cpu version on another linux machine and I used pip install git+https://github.com/fastai/fastai.git, but did not tested it on docker yet.

Still hope that ImportError: Failed to import any qt binding can be solved in some way.

As for now, I find the next workaround (which might not be that good):

  1. ship the ufoym/deepo:py36-jupyter-cpu docker image
  2. inside the docker container use pip install git+https://github.com/fastai/fastai.git to install the fastai lib
  3. if got ImportError: No module named ‘_tkinter’, please install the python3-tk package install the package via apt-get update && apt-get install python3-tk

Here is a Dockerfile that builds the latest version of fast.ai from github: https://raw.githubusercontent.com/mattmcclean/sagemaker-fastai-container/master/docker/Dockerfile.base

The base image can be pulled from DockerHub by using the following command:

docker pull mattmcclean/fastai-base

@matt.mcclean This image cannot be found:

Error response from daemon: manifest for mattmcclean/fastai-base:latest not found

Whoops, I forgot to add the correct tag. Use this command instead:

docker pull mattmcclean/fastai-base:0.3.1-gpu-py36