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

Unable to use Python extension on Mac #59

Closed kdheepak closed 6 years ago

kdheepak commented 6 years ago

I'm installing from source using HELICS develop branch and using Python 3.6

➜  python
Python 3.6.3 |Anaconda, Inc.| (default, Dec  5 2017, 17:30:25)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import helics
Fatal Python error: PyThreadState_Get: no current thread

[1]    99554 abort      python

There are no build errors, but when I import helics it causes a fatal python error.

kdheepak commented 6 years ago

I tried this with both clang and gcc and I still get the same error.

phlptp commented 6 years ago

Do you know when the error occurs, immediately, at some point, or during closing?

kdheepak commented 6 years ago

That is what I'll be trying next. I'm going through this step by step.

I tested SWIG with a trivial example, and I was able to successfully compile and import the Python extension there. I did not use CMake for this.

I then tested this with Mac System Python 2.7, but it threw a Boost error on import.

Currently, I'm using CMake to build the Python extension. I tried the following and it still failed.

gcc -shared helicsPYTHON_wrap.c $(python-config --includes) -I/path/to/HELICS-src/src/helics/shared_api_library -L/path/to/helics-install-0.9/lib -lhelicsSharedLib -L$(python-config --prefix)/lib -lpython3.6m -o _helics.so

It fails on import helics. Googling seems to suggest that the problem is because of multiple versions of Python. When using CMake this is the output of all Python variables.

-- Found SWIG: /Users/$USER/miniconda3/bin/swig (found version "3.0.12")
-- Found PythonLibs: /Users/$USER/miniconda3/lib/libpython3.6m.dylib (found version "3.6.3")
-- Found PythonInterp: /Users/$USER/miniconda3/bin/python3.6 (found version "3.6.3")
PYTHON_LIBRARY : /Users/$USER/miniconda3/lib/libpython3.6m.dylib
PYTHON_INCLUDE_DIR : /Users/$USER/miniconda3/include/python3.6m
PYTHONLIBS_FOUND : TRUE
PYTHON_LIBRARIES : /Users/$USER/miniconda3/lib/libpython3.6m.dylib
PYTHON_INCLUDE_PATH : /Users/$USER/miniconda3/include/python3.6m
PYTHON_INCLUDE_DIRS : /Users/$USER/miniconda3/include/python3.6m
PYTHON_DEBUG_LIBRARIES :
PYTHONLIBS_VERSION_STRING : 3.6.3
PYTHONINTERP_FOUND: TRUE
PYTHON_EXECUTABLE: /Users/$USER/miniconda3/bin/python3.6
PYTHON_VERSION_STRING: 3.6.3
PYTHON_VERSION_MINOR: 6
PYTHON_VERSION_MAJOR: 3
PYTHON_VERSION_PATCH: 3

I'll try using gdb to see if I can figure out the exact line it is failing at.

kdheepak commented 6 years ago

Well, if I create a conda Python 2.7 environment it works. But not if I use root Python 3 nor if I use a conda Python 3.6 environment. I have a feeling it's somehow picking up something from the default mac system Python 2.7 installation. I'm going to post on stackoverflow to see if I get any other answers.

kdheepak commented 6 years ago

I posted on StackOverflow to see if anyone is able to offer any suggestions - https://stackoverflow.com/questions/48123074/fatal-python-error-pythreadstate-get-no-current-thread

kdheepak commented 6 years ago

The second method of building the extension allows use of Python3.6 using Anaconda3/Miniconda3 on Mac.

kdheepak commented 6 years ago

This is fixed, and no more workaround required. Tested on homebrew Python 2.7.14 + homebrew Python 3.6.4 + anaconda Python 2.7.14 + anaconda Python 3.6.1 + anaconda Python 3.6.4.

kdheepak commented 6 years ago

PR #112 addresses this issue.