qpv-research-group / rayflare

Open-source, integrated optical modelling of complex stacks
Other
31 stars 11 forks source link

Installation problem of S4 #50

Closed yangfan256 closed 1 year ago

yangfan256 commented 2 years ago

Hi there!

It's nice to see that you are maintaining S4 and extending it to python3. However, I meet an installation problem related with "#include Python.h". It seems the python.h file is missing. I have upgraded all the dependencies that you mentioned before the installation, but the problem occurs. The error information is as follows, after I commanded "make S4_pyext". Do you have any suggestions?

Thanks!

mkdir -p ./build mkdir -p ./build/S4k mkdir -p ./build/S4r mkdir -p ./build/modules ar crvs build/libS4.a ./build/S4k/S4.o ./build/S4k/rcwa.o ./build/S4k/fmm_common.o ./build/S4k/fmm_FFT.o ./build/S4k/fmm_kottke.o ./build/S4k/fmm_closed.o ./build/S4k/fmm_PolBasisNV.o ./ build/S4k/fmm_PolBasisVL.o ./build/S4k/fmm_PolBasisJones.o ./build/S4k/fmm_experimental.o ./build/S4k/fft_iface.o ./build/S4k/pattern.o ./build/S4k/intersection.o ./build/S4k/predicates. o ./build/S4k/numalloc.o ./build/S4k/gsel.o ./build/S4k/sort.o ./build/S4k/kiss_fft.o ./build/S4k/kiss_fftnd.o ./build/S4k/SpectrumSampler.o ./build/S4k/cubature.o ./build/S4k/Interpolat or.o ./build/S4k/convert.o r - ./build/S4k/S4.o r - ./build/S4k/rcwa.o r - ./build/S4k/fmm_common.o r - ./build/S4k/fmm_FFT.o r - ./build/S4k/fmm_kottke.o r - ./build/S4k/fmm_closed.o r - ./build/S4k/fmm_PolBasisNV.o r - ./build/S4k/fmm_PolBasisVL.o r - ./build/S4k/fmm_PolBasisJones.o r - ./build/S4k/fmm_experimental.o r - ./build/S4k/fft_iface.o r - ./build/S4k/pattern.o r - ./build/S4k/intersection.o r - ./build/S4k/predicates.o r - ./build/S4k/numalloc.o r - ./build/S4k/gsel.o r - ./build/S4k/sort.o r - ./build/S4k/kiss_fft.o r - ./build/S4k/kiss_fftnd.o r - ./build/S4k/SpectrumSampler.o r - ./build/S4k/cubature.o r - ./build/S4k/Interpolator.o r - ./build/S4k/convert.o sh gensetup.py.sh ./build ./build/libS4.a "-lblas -llapack -lfftw3 -lcholmod -lamd -lcolamd -lcamd -lccolamd -L/home/yangfan/S4/S4/lib/ -lboost_serialization" /home/yangfan/S4/S4 LIBFILE: ./build/libS4.a pip3 install --upgrade ./ Defaulting to user installation because normal site-packages is not writeable Processing /home/yangfan/S4 Preparing metadata (setup.py) ... done Building wheels for collected packages: S4 Building wheel for S4 (setup.py) ... error error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [10 lines of output] running bdist_wheel running build running build_ext building 'S4' extension x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack -protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/yangfan/S4/S4/include -I/home/yangfan/.local/lib/python3.8/site-packages/numpy/core/inclu de -I/usr/include/python3.8 -c S4/main_python.c -o build/temp.linux-x86_64-3.8/S4/main_python.o -std=gnu99 S4/main_python.c:20:10: fatal error: Python.h: No such file or directory

include "Python.h"

            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for S4 Running setup.py clean for S4 Failed to build S4 Installing collected packages: S4 Running setup.py install for S4 ... error error: subprocess-exited-with-error

× Running setup.py install for S4 did not run successfully. │ exit code: 1 ╰─> [12 lines of output] running install running build running build_ext building 'S4' extension creating build/temp.linux-x86_64-3.8 creating build/temp.linux-x86_64-3.8/S4 x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack -protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/yangfan/S4/S4/include -I/home/yangfan/.local/lib/python3.8/site-packages/numpy/core/inclu de -I/usr/include/python3.8 -c S4/main_python.c -o build/temp.linux-x86_64-3.8/S4/main_python.o -std=gnu99 S4/main_python.c:20:10: fatal error: Python.h: No such file or directory

include "Python.h"

            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure

× Encountered error while trying to install package. ╰─> S4

note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure. WARNING: You are using pip version 22.0.4; however, version 22.1.2 is available. You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command. Makefile:351: recipe for target 'S4_pyext' failed make: *** [S4_pyext] Error 1

phoebe-p commented 2 years ago

It is probably related to this, I have also previously had this issue if I did not install python3-dev: https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory

There are instructions there for different Linux distributions

yangfan256 commented 2 years ago

Thanks for your reply! But I have checked the python3-dev and it is the newest version, so maybe there is another potential problem?

phoebe-p commented 2 years ago

I'm not aware of another cause, sorry -- apologies if this is obvious (I don't know if you are experienced with Python), but is it possible that you have multiple versions of Python installed (i.e. Python 3.6 and Python 3.8, or Anaconda Python and 'normal' Python)? It may be that the python3-dev you installed is not actually for the Python executable you are using to try to install S4. These instructions are slightly outdated now (since new versions of Ubuntu come with Python 3.8 by default and Python 3.9 is now available), but here are all the steps I have used previously to set up my Python environment prior to installing S4:

https://rayflare.readthedocs.io/en/latest/Installation/python_install.html

yangfan256 commented 2 years ago

Thanks for your suggestions and I have checked my python version. Yes, there are several versions for python3 and I am using python3.8, so I install the python3.8-dev and the problem get solved!

However, when I try to test if the module works well and run the PythonTest.py, the error shows that

AttributeError: partially initialized module 'S4' has no attribute 'New' (most likely due to a circular import)

and I do find that the attributes are not available after I import S4.

Sorry to bother again...

yangfan256 commented 2 years ago

I found the S4 is too old for python, and the original author Victor Liu does not maintain the python extension himself. What S4 attracts me most is that it could deal with anisotropic dielectrics.

phoebe-p commented 2 years ago

I'm not sure what the issue is, but it might be because you are trying to run things while the active working directory (for Python) is the directory where you downloaded S4? This way it might be trying to import from the S4 folder locally rather than from the compiled, installed version. So maybe trying copying the example to a different directory and running it there.

P.S. It is not in the current version, but I have been working on implementing anisotropic materials in RayFlare itself (the work I've done so far is in the anistropic_mat branch, in case it is of interest to you.

yangfan256 commented 2 years ago

Thank you a lot! I guess you are right. Now the S4 can work in my server.