3

So here is the beginning of my code:

#!/usr/bin/python

import h5py
f = h5py.File("/data/vera/run-2/hdfaa.001","r")

When I run it, it works well in the home directory. But when I run this in the directories inside the home directory, there is the error printed:

Traceback (most recent call last):
File "h5py.py", line 3, in <module>
import h5py
File "/.../h5py.py", line 5, in <module>
f = h5py.File("/...","r")
AttributeError: 'module' object has no attribute 'File'

When I use IPython of python interpreter, it can import the library and have the attribute h5py.File. But once I have the script interpreted, the interpreter cannot import the h5py library anymore. After I have deleted the file, it works fine again.

I have used the interpreter to check my script and there shouldn't be any problem with the scripting.

Since I am quite new to python, so I have no idea where goes wrong.

V. Wu
  • 39
  • 1
  • 2
  • 3
    Change the name of your `h5py.py` file. It is hiding the `h5py` that you want to import. – hpaulj Mar 04 '17 at 07:20
  • Let me add, for future use, that there can be no 'h5py.py' in the folder. So if you created one earlier, it is still covering you working file. – Mathias Oct 31 '19 at 12:36

1 Answers1

0

This worked for me:

  • Uninstall h5py : pip uninstall h5py
  • Install h5py : pip install h5py

Actually I checked the h5py package that was already present, and it seemed corrupted to me. So I did the obvious, and voila, it worked!

Mooncrater
  • 4,146
  • 4
  • 33
  • 62