tudo-astroparticlephysics / PROPOSAL

Monte Carlo Simulation propagating charged Leptons through Media as C++ Library
GNU Lesser General Public License v3.0
35 stars 21 forks source link

Python bindings not working on MacOS when using anaconda #209

Open Jean1995 opened 3 years ago

Jean1995 commented 3 years ago

There is an issue on MacOS machines using anaconda when trying to import proposal in Python.

The installation (either using pip or manually) is working fine, however, import proposal leads to the error

Fatal Python error: PyMUTEX_LOCK(gil->mutex) failed
Python runtime state: unknown

or

zsh: segmentation fault  python3

Apparently, this is an issue with pybind11 (see here or here or here). The discussions say that this might have to do with conda python and the python package being built with different Clang versions. However, the issue does not seem to be resolved, and I couldn't find any viable solutions for this issue yet.

There is a github actions run where the issue has been reproduced, although I am not entirely sure whether this is the same problem (see here)

maxnoe commented 3 years ago

Does compiling proposal with the conda compiler work?

This also might be a reason to do a conda forge package.

Jean1995 commented 3 years ago

@pascalgutjahr and I tried using the conda compiler by using conda install -c conda-forge compilers without success.

Looking at the pybind11 issue there seems to be a lively discussion on the problem now, but I did not find the time to work through all the ideas that were brought up. But it looks like the problem is also connected to conan and the way pybind11 is packaged there.

So for now, the easiest solution is probably to try installing PROPOSAL without conan, i.e. installing all dependencies manually.

pascalgutjahr commented 3 years ago

The installation still does not work with conda, but it works in a virtual environment for both OS X 11.6 and 10.15.7. For the installation you can use the way via conan. I have done it in the following way:

conda deactivate
python3 - m venv proposal_env
export PYTHONPATH=/Users/pgutjahr/Documents/PROPOSAL/build/package/lib:$PYTHONPATH

It's import to add the path of the PROPOSAL library to the PYTHONPATH, otherwise python can not find the module. Since I usually activate the conda environment in my .bash_profile, I added the deactivation of conda and the export of the PYTHONPATH to the activation script of my virtual environment. So you just have to source the virtual environment and you are able to run PROPOSAL.

Jean1995 commented 8 months ago

As the problem is still not fixed, the simplest workaround to install proposal via pip is still:

conda deactivate #in case you are still in your conda base environment
python3 - m venv proposal_env
pip install proposal