0

Does anybody know how to install h5py on datalab? pip install h5py doesn't work. apt-get install python-h5py is working in the shell but it doesn't recognize the package in datalab notebook!

Thnaks

Nima
  • 55
  • 8

2 Answers2

2

It is true that !pip install h5py wil allow you to install the library but unfortunately, even after a successful installation, the import will fail: enter image description here

The issue is rooted on an ongoing python-future issue ("surrogateescape handler broken when encountering UnicodeEncodeError") that is experienced in datalab because the underlying OS uses an 'ANSI_X3.4-1968' file system encoding.

As a hacky workaround, you may remove line 60 from h5py's __init__.py by running the following command from within a notebook cell:

!sed -i.bak '/run_tests/d' /usr/local/lib/python2.7/dist-packages/h5py/__init__.py
Mar Cial R
  • 936
  • 9
  • 20
  • If the OP doesn't need the latest version, `pip install -U h5py==2.6` is probably a cleaner solution, until that issue is fixed. Make sure no dependencies are changed though. – yelsayed Apr 19 '17 at 17:38
1

Just make sure you run it using bash syntax: !pip install h5py in any notebook cell.

yelsayed
  • 5,236
  • 3
  • 27
  • 38