Reputation: 345
I want to read Fortran 90 binary files in Python and hence there is this module which has been developed for that in Scipy called as "fortranFile", as given here fortranFile module
How do I include this module in python so that I can call it from my code like
import fortranFile
f = fortranFile('file.bin')
x = f.readReals('f')
print x
right now, I get the error
Traceback (most recent call last):
File "readfortbin.py", line 5, in <module>
from fortranFile import fortranFile
ImportError: cannot import name fortranFile
I made a folder "fortranFile" in my /usr/lib/python2.7/dist-packages directory and added the "fortranFile.py" file to that folder. I know that I am missing something... Please suggest how I should proceed.
Upvotes: 0
Views: 3791
Reputation:
To quickly address your question, I think your import statement is wrong. Specifically I think from fortanFile import fortranFile
should be from fortranFile import FortranFile
. It is convention in Python is to capitalize every word in a class name.
On a different note there is a more up-to-date version of the module you're trying to install here and in the Python Package Index. You can easily install it using the Python package installer pip
.
Important note: fortranfile
depends on the popular numpy
numerical analysis package.
On my Ubuntu 13.04 system I had to perform the following steps:
apt-get install -y libpython-dev # For compiling the numpy C wrappers.
# May alternatively be called python-dev or python-devel.
pip install numpy
pip install fortranfile
Upvotes: 2