GMLC-TDC / HELICS

Hierarchical Engine for Large-scale Infrastructure Co-Simulation (HELICS)
https://docs.helics.org/en/latest/
BSD 3-Clause "New" or "Revised" License
127 stars 41 forks source link

`Python.h` not found building python extension on OSX #114

Closed bpalmintier closed 6 years ago

bpalmintier commented 6 years ago

Following the latest swig\python\README.md directions on Mac from within an anaconda 3.64 virtual environment and got the following error (Note on: develop 50fd510311)

(python36) bpalmint-31532s:build-osx bpalmint$ cmake -DCMAKE_INSTALL_PREFIX=/Users/$USER/helics_install -DBUILD_PYTHON=ON -DBUILD_SHARED_LIBS=ON -DPYTHON_LIBRARY=$(python-config --prefix)/lib/libpython3.6m.dylib -DPYTHON_INCLUDE_DIR=$(python-config --prefix)/include/python3.6m ../

...

(python36) bpalmint-31532s:build-osx bpalmint$ make clean
(python36) bpalmint-31532s:build-osx bpalmint$ make -j4

...

Scanning dependencies of target _helics
make[2]: *** No rule to make target `/Users/bpalmint/anaconda/lib/libpython3.6m.dylib', needed by `swig/python/_helics.so'.  Stop.
make[2]: *** Waiting for unfinished jobs....
[ 96%] Building C object swig/python/CMakeFiles/_helics.dir/helicsPYTHON_wrap.c.o
/Users/bpalmint/repos/HELICS-src/build-osx/swig/python/helicsPYTHON_wrap.c:149:11: fatal error: 
      'Python.h' file not found
# include <Python.h>
          ^~~~~~~~~~
1 error generated.
make[2]: *** [swig/python/CMakeFiles/_helics.dir/helicsPYTHON_wrap.c.o] Error 1
make[1]: *** [swig/python/CMakeFiles/_helics.dir/all] Error 2

...

(python36) bpalmint-31532s:build-osx bpalmint$ make

...

[100%] Building C object swig/python/CMakeFiles/_helics.dir/helicsPYTHON_wrap.c.o
/Users/bpalmint/repos/HELICS-src/build-osx/swig/python/helicsPYTHON_wrap.c:149:11: fatal error: 
      'Python.h' file not found
# include <Python.h>
          ^~~~~~~~~~
1 error generated.
make[2]: *** [swig/python/CMakeFiles/_helics.dir/helicsPYTHON_wrap.c.o] Error 1
make[1]: *** [swig/python/CMakeFiles/_helics.dir/all] Error 2
make: *** [all] Error 2
kdheepak commented 6 years ago

I think I know what the problem is. It should be python3-config instead of python-config. The instructions on the develop branch are not up to date. They have been updated on add-install-target-for-swig-python. python-config by default defaults to python2-config which is why this does not work.

bpalmintier commented 6 years ago

That got the compilation to work, but still unable to run python extension. It seems the file directories don't match the install directions in two ways:

After running (output suppressed, no errors):

$ cmake -DCMAKE_INSTALL_PREFIX=~/helics_install -DBUILD_PYTHON=ON -DPYTHON_LIBRARY=$(python3-config --prefix)/lib/libpython3.6m.dylib -DPYTHON_INCLUDE_DIR=$(python3-config --prefix)/include/python3.6m ../
$ make -j4
$ make
$ make install

There is no python folder under ~/helics_install

$ ls ~/helics_install/
bin/     cmake/   include/ lib/

And there are no pireceiver.py or pisender.py in .../repos/HELICS-src/build-osx/swig/python:

(python36) bpalmint-31532s:python bpalmint$ pwd
/Users/bpalmint/repos/HELICS-src/build-osx/swig/python
(python36) bpalmint-31532s:python bpalmint$ ls
CMakeFiles/          Makefile             cmake_install.cmake  helicsPYTHON_wrap.c
CTestTestfile.cmake  _helics.so*          helics.py

And not sure if still a valid test, but trying to run helics.py still produces the abort trap:

(python36) bpalmint-31532s:python bpalmint$ export PYTHONPATH="~/helics_install/python"
(python36) bpalmint-31532s:python bpalmint$ python helics.py 
Fatal Python error: PyThreadState_Get: no current thread

Abort trap: 6
kdheepak commented 6 years ago

@bpalmintier Thanks for following up on this and keeping us honest. The changes were on the branch that hadn't been merged to develop yet, I just merged it this morning. See the README.md in develop. I still need to update the Python examples pireceiver.py and pisender.py though. I will do that and comment here again.

kdheepak commented 6 years ago

I tested these examples now and they work. You can follow the README.md on the latest commit of develop.

phlptp commented 6 years ago

@kdheepak can we close this issue?

kdheepak commented 6 years ago

I'm waiting for @bpalmintier to confirm this is resolved. I think with the new changes + brew installation steps we should be good. I'll confirm and close by tomorrow.

bpalmintier commented 6 years ago

Closing. Current develop branch works. I also updated the python README.md to fully explain the steps for testing (including starting the broker). See 3952052

bpalmintier commented 6 years ago

Note: Tested via README.md steps, not using brew install

kdheepak commented 6 years ago

Thanks testing and for making the README.md more thorough! On a related note, I'm going move all documentation to the docs folder along with how to run the examples, since users are more likely to check the website than check the README.md in a folder or on github.

bpalmintier commented 6 years ago

Great idea. Strongly like moving them out of their currently buried position.