Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not link to libpython on MacOS with Anaconda Python #3088

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmake/PythonHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ function(nrn_find_python)
PARENT_SCOPE)
endfunction()

# Check if Python from Conda is being used on MacOS
if(NRN_MACOS_BUILD)
string(FIND "${PYTHON_EXECUTABLE}" "/anaconda" anaconda_found)
string(FIND "${PYTHON_EXECUTABLE}" "/miniconda" miniconda_found)
if(anaconda_found GREATER -1 OR miniconda_found GREATER -1)
set(NRN_WITH_MACOS_CONDA_PYTHON TRUE)
endif()
endif()

# For each Python in NRN_PYTHON_EXECUTABLES, find its version number, its include directory, and its
# library path. Store those in the new lists NRN_PYTHON_VERSIONS, NRN_PYTHON_INCLUDES and
# NRN_PYTHON_LIBRARIES. Set NRN_PYTHON_COUNT to be the length of those lists, and
Expand Down
10 changes: 10 additions & 0 deletions docs/install/install_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,13 @@ If it prints `2.0` or higher, try installing an older version:
pip install "numpy<2"
```
(mind the quotes.) Then delete the build directory, reconfigure and compile. If the error persists, carefully check which version of Python NEURON picked up by checking the output of the CMake configure command and make sure that that exact version of Python doesn't pick up an incompatible version of Numpy.


* **NEURON segfaults when using the Anaconda Python distribution. What can I do?**

Some Anaconda distributions (e.g., macOS) ship Python binaries with `libpython` statically linked,
which has caused issues in NEURON and other packages (see discussion [here](https://github.com/neuronsimulator/nrn/issues/2358)).

On the macOS platform, NEURON attempts to detect the use of Anaconda Python by checking for the `/anaconda`
prefix in the Python binary path. An alternative solution is to build NEURON with the dynamic Python
option enabled, using the CMake flag `-DNRN_ENABLE_PYTHON_DYNAMIC=ON`.
5 changes: 4 additions & 1 deletion src/nrnpython/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ else()
set_property(TARGET nrnpython PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(nrnpython PUBLIC ${INCLUDE_DIRS})
target_include_directories(nrnpython PUBLIC "${NRN_DEFAULT_PYTHON_INCLUDES}")
target_link_libraries(nrnpython ${NRN_DEFAULT_PYTHON_LIBRARIES})
# see nrn/issues/2358
if(NOT NRN_WITH_MACOS_CONDA_PYTHON)
target_link_libraries(nrnpython ${NRN_DEFAULT_PYTHON_LIBRARIES})
endif()
target_link_libraries(nrnpython fmt::fmt)
target_include_directories(nrnpython PUBLIC ${PROJECT_SOURCE_DIR}/${NRN_3RDPARTY_DIR}/eigen)
target_include_directories(nrnpython PUBLIC ${PROJECT_BINARY_DIR}/src/nrniv/oc_generated)
Expand Down
Loading