I have performed a ‘git pull’ today 27-08-2018 and for the fun off it I thought I would run ‘pytest tests’. However this fails with an import error for module ‘cv2’. I know on mac OS X 10.11.06 there is an issue with ‘opencsv’ see http://forums.fast.ai/t/issues-with-import-of-cv2-on-mac-os-x-10-11-6/12920/2
My version of ‘opencsv’ is 3.3.1 which imports without error from python at a terminal. However when I run ‘pytest tests’ I get this error.
ImportError while importing test module ‘/Users/mac/FASTAI/fastai/tests/test_core.py’.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/init.py:3: in
import cv2,torch
E ModuleNotFoundError: No module named ‘cv2’
Note there should be 2 underscores either side of the init in tests/init.py but get lost in the posting of this message.
repeated for other test modules
- test_dataset
- test_layer_optimizer
- test_lsuv_initialize
- test_samplers
- test_structured
- test_transform
However the code in init.py seems to be a fix for ubuntu 16.04. Also ‘cv2’ is only used in 2 modules
- test_lsuv_initializer.py:import cv2 :: which imports it again
- test_transform.py :: which relies on the ‘__ init __.py’ import from 'test_core.py
I have raised an issue on github and then noted issue about testfixtures which I added to my cpu environment which did not remove the error.
Also I think it is an issue not just for cv2 but for other modules as well. It may be in my use of pytest. However I am following instructions on the github page.
I have solved this issue by:
- running command
pytest tests
from a terminal in thefastai
directory - delete / rename
tests/__init__.py
file - set
PYTHONPATH=../fastai
to allow the tests to findfast module
- added the equivalent of
sys.path
forfastai-cpu
toPYTHONPATH
export PYTHONPATH=../fastai:/Users/mac/anaconda3/envs/fastai-cpu/lib/python36.zip:/Users/mac/anaconda3/envs/fastai-cpu/lib/python3.6:/Users/mac/anaconda3/envs/fastai-cpu/lib/python3.6/lib-dynload:/Users/mac/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages:/Users/mac/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages/aeosa
- 69 tests passed a one was skipped
- I was able to reinstate the
__init__.py
file and the tests passed, one skipped