H5py: unittest2 is required with python 2.x but it is not in install_requires

Created on 9 Mar 2018  路  4Comments  路  Source: h5py/h5py

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

Most helpful comment

use this command can solve the problem in python 2.7
sudo pip install unittest2

All 4 comments

I can propose a fix, but what do you prefer:

  • adding unittest2 as a runtime dependency for python2
  • using lazy-loading of run_tests in h5py/__init__.py

The '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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalvdans picture kalvdans  路  8Comments

ax3l picture ax3l  路  3Comments

linxd5 picture linxd5  路  6Comments

272437543 picture 272437543  路  4Comments

1313e picture 1313e  路  8Comments