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

Importing proposal in conda not working on ubuntu? #381

Open Jean1995 opened 10 months ago

Jean1995 commented 10 months ago

When trying to import proposal after installing it with pip install proposal from inside the environment, and then try to import it, I get the error message:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

I don't know there this is coming from.

Jean1995 commented 10 months ago

Possibly related to #327?

maxnoe commented 10 months ago

@Jean1995 Seems to be identical to #327 (you are both using conda on ubuntu)

Jean1995 commented 10 months ago

Yes, creating a new conda environment and installing proposal there fixed it. But this shouldn't be the default solution in my opinion, something must still be going wrong...

maxnoe commented 10 months ago

I just tried it with a fresh environment using python 3.11 and I get the same error:

mamba create -n proposal python=3.11 pip  
mamba activate proposal
pip install -vv proposal   
python -c 'import proposal'      
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: libpython3.11.so.1.0: cannot open shared object file: No such file or directory
maxnoe commented 10 months ago

It works when building proposal using the conda compilers and not sthe system compilers, i.e. with this environment:

mamba create -n proposal-conda-compilers python=3.11 pip compilers
Jean1995 commented 10 months ago

In the setup.py, we set the python executable via

https://github.com/tudo-astroparticlephysics/PROPOSAL/blob/c3b01b7a7006674c9f83db8ea20f882f7169029b/setup.py#L104

is this maybe not the correct way?

maxnoe commented 10 months ago

Looking into the build log file, it is using the correct python to compile, but then at runtime it doesn't find the corresponding library.

Note that the version of the library not being found is the one in the conda env, so the compilation step was correct.

I think the issue is wrong RPATH information.

thomwg11 commented 10 months ago

I'm experiencing what I believe to be a similar issue on an M1 Mac running macOS and trying to pip install proposal in a conda environment, except in my case importing proposal results in a segmentation fault.

Jean1995 commented 10 months ago

I'm experiencing what I believe to be a similar issue on an M1 Mac running macOS and trying to pip install proposal in a conda environment, except in my case importing proposal results in a segmentation fault.

This sounds like the problem in issue #209, which might very well also be related to this problem.

maxnoe commented 10 months ago

I think this line might be at fault:

https://github.com/tudo-astroparticlephysics/PROPOSAL/blob/c3b01b7a7006674c9f83db8ea20f882f7169029b/setup.py#L107

The link path of the libpython should probably be used, at least in case of a conda installation.

maxnoe commented 10 months ago

Or adapt the lines here:

https://github.com/tudo-astroparticlephysics/PROPOSAL/blob/c3b01b7a7006674c9f83db8ea20f882f7169029b/setup.py#L79

to include the library, best as a relative path from the python module.

pyproposal will be installed to something like <prefix>/lib/site-packages/pythonxy/ so you could try to add $ORIGIN/../../../

Jean1995 commented 10 months ago

These lines were added in #80, more specifically in commit 75392b6067d5037d8182d43cc9de4b61bb1824e3. Apparently there were some issues with MacOS (as usual...)