djlampert / PyHSPF

Python extensions to the Hydrological Simulation Program in Fortran (HSPF), including classes for gathering input data, building input files, performing simulations, postprocessing results, calibrating hydrology process parameters, and forecasting climate and land use change effects on water resources
Other
83 stars 51 forks source link

Compilation on linux #8

Closed cheginit closed 5 years ago

cheginit commented 5 years ago

I tried to compile the code on Ubuntu 18.04 with python3 but get the following error:

$ python3 setup.py config --compiler=gcc build --compiler=gcc
...
...
build_src: building npy-pkg config files
running build_py
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with 'gcc' compiler

I installed the prerequisites using apt and am not using Anaconda.

djlampert commented 5 years ago

I have not seen this problem before. Can you try just compiling the "C" files in the src/hspf13 directory without python from the command line?

cheginit commented 5 years ago

It seems to be compiled as expected. I attached the log: gcc.log

djlampert commented 5 years ago

The log says in it "error." Can you successful compile the four c files into objects? gcc -c *.c?

djlampert commented 5 years ago

I don't think you need to specify the compiler flags on linux. It should be pretty straightforward...python3 setup.py build then sudo python3 setup.py install. The other instructions are for windows. If this works for you, I will try to update the readme to clarify.

cheginit commented 5 years ago

I tried it without the compiler flag as you mentioned but gives the following error:

....
No module named 'numpy.distutils.cygwinccompiler' in numpy.distutils; trying from distutils
....

I attached the log. I think use of this module is hardcoded so it cannot use a compiler based on the OS. noflag.log

cheginit commented 5 years ago

I was looking at the setup.py and have a minor suggestion, line 145:

files = ['hspf13/{}'.format(f)
         for f in os.listdir('hspf13')
         if f[-1] == 'c' or f[-1] == 'f']

can be replaced by:

files = glob.glob('hspf13/*.[c,f]')
cheginit commented 5 years ago

I just saw your gcc comment. Yes, I can successfully compile with gcc -c *.c without any error.

wk1984 commented 5 years ago

Try: python3 setup.py config --compiler=unix build --compiler=unix It seems like to work with default gcc and gfortran compiler.

Also, including install should be fine:

python3 setup.py config --compiler=unix build --compiler=unix install

cheginit commented 5 years ago

It worked. Thanks. Also, I had to add a user flag to avoid "permission denied":

$> python3 setup.py config --compiler=unix build --compiler=unix install  --user
djlampert commented 5 years ago

Great to hear. I am going to go ahead and close this issue then. Thank you Kong, and I hope you both are getting some value from this effort!

abhiramp1 commented 4 years ago

If anyone is still trying to install pyhspf in their linux systems, you need to delete config file and then build using command python3 setup.py build. After building install pyhspf by $python3 setup.py install$