With h5py 2.8.0rc1 (installed from pypi wheels) on Python2.7, unittest2 is required to import h5py but it is not listed in setup.py's install_requires.
I tested on Linux and Windows but it should affect all platform with python 2.x:
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[...]/lib/python2.7/site-packages/h5py/__init__.py", line 67, in <module>
from .tests import run_tests
File "[...]/lib/python2.7/site-packages/h5py/tests/__init__.py", line 13, in <module>
from .common import ut
File "[...]/python2.7/site-packages/h5py/tests/common.py", line 27, in <module>
raise ImportError( "unittest2 is required to run tests with Python 2")
ImportError: unittest2 is required to run tests with Python 2
I can propose a fix, but what do you prefer:
unittest2 as a runtime dependency for python2run_tests in h5py/__init__.pyThe 'right' thing to do would be to be lazy about importing run_tests, but that could be a pretty disruptive API change.
try:
from .tests import run_tests
except ImportError:
def run_tests():
import unittest2 # or some nicer exception
would keep the API and defer the import error until it is actually used.
Adding unittest2 as a dep is a bit dirty, but is the simplest fix.
use this command can solve the problem in python 2.7
sudo pip install unittest2
Running sudo pip is generically an extremely bad idea as it will introduce conflicts with your system's package manager. Only do this if you are sure of what you are doing.
Most helpful comment
use this command can solve the problem in python 2.7
sudo pip install unittest2