PyMultiNest icon indicating copy to clipboard operation
PyMultiNest copied to clipboard

Unable to run using MacOSX

Open adj-smith opened this issue 4 years ago • 14 comments

I consistently get the following when attempting to execute PyMultiNest:

Traceback (most recent call last): File "/Users/[redacted]/Documents/Code/Internal/PMNexperimentMay2020.py", line 139, in <module> pmn.run(Loglike, Prior, ndims,n_live_points=1000,n_params=n_params,outputfiles_basename='./'+ProjectName+'/temp_',resume=False,verbose=True) File "/Users/ajsmit16/Library/Python/3.8/lib/python/site-packages/pymultinest-2.9-py3.8.egg/pymultinest/run.py", line 254, in run File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__ func = self.__getitem__(name) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: dlsym(RTLD_DEFAULT, run): symbol not found

This is likely related to Issue #160 however the solutions mentioned there did not work for me. I am executing using Python 3 running on macOS Catalina version 10.15.4. I can provide any additional information as needed.

adj-smith avatar May 22 '20 18:05 adj-smith

Try to recompile multinest (clean the build directory beforehand).

JohannesBuchner avatar May 22 '20 19:05 JohannesBuchner

Thank you for the quick response. In the MultiNest/Build/ directory I ran make clean followed by make and then attempted to run PMN again. I encountered the same error.

adj-smith avatar May 22 '20 19:05 adj-smith

Additional information, in case it is helpful.

[redacted]:build [redacted]$ echo $DYLD_LIBRARY_PATH

/Users/[redacted]/MultiNest/lib/:/Users/[redacted]/MultiNest/lib/:/Users/[redacted]/MultiNest/lib/:/Users/[redacted]/MultiNest/lib/:

[redacted]:build [redacted]$ ls -al /Users/[redacted]/MultiNest/lib
total 2920

drwxr-xr-x   6 [redacted]  staff     192 May 22 15:51 .

drwxr-xr-x  16 [redacted]  staff     512 May 22 14:16 ..

-rw-r--r--   1 [redacted]  staff     120 May 22 11:52 .gitignore

-rwxr-xr-x   1 [redacted]  staff  680812 May 22 15:51 libmultinest.3.10.dylib

-rw-r--r--   1 [redacted]  staff  803424 May 22 15:51 libmultinest.a

lrwxr-xr-x   1 [redacted]  staff      23 May 22 15:51 libmultinest.dylib -> libmultinest.3.10.dylib

adj-smith avatar May 22 '20 20:05 adj-smith

clean the build directory completely and rerun cmake.

JohannesBuchner avatar May 23 '20 05:05 JohannesBuchner

I am still having the issue. I attempted to follow your suggestion. I completely deleted the /MultiNest/ directory, did another git clone, and ran cmake and make again (as sudo just to be sure). However I still encounter the AttributeError on execution.

Possibly related: the documentation refers to the creation of a libmultinest.so shared object in the MultiNest/lib/ directory. However after cmake/make the only files in that directory for me are .dylib and .a files.

adj-smith avatar May 26 '20 15:05 adj-smith

Use ldd to identify the libraries needed by libmultinest.so (ldd libmultinest.so). check with which python (or python3) the python runtime actually used (is it conda?). Then use ldd on it.

Alternatively, you can try UltraNest instead.

JohannesBuchner avatar May 26 '20 15:05 JohannesBuchner

there is also a conda pymultinest package, which installs multinest for you.

JohannesBuchner avatar May 26 '20 15:05 JohannesBuchner

@grburgess suggests that using sudo is unwise, as it can mix python environments. Try without?

JohannesBuchner avatar May 26 '20 16:05 JohannesBuchner

otool -L is the Mac equivalent of ldd.

$ otool -L /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3:
    /Library/Frameworks/Python.framework/Versions/3.8/Python (compatibility version 3.8.0, current version 3.8.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

I will take a look at UltraNest and Conda, I have no experience with either. It would be nice to use PMN again, I am familiar with it from research in past years.

Presence or absence of sudo does not appear to affect the result.

Thank you for your assistance. As I said I will try UltraNest, and failing that I think I will use a different environment (I have access to a remote machine in addition to my current system) to see if that makes any difference. If you have any other suggestions I'll try those as well.

adj-smith avatar May 26 '20 16:05 adj-smith

I think I see something that is a potential problem.

Are you using a virtual environment?

It seems you are also using the MacOS system python, rather than one installed via a package manager or manually. This can cause a gigantic number of issues that are difficult to trace because things become linked to system libraries.

Are you using the system python?

grburgess avatar May 28 '20 09:05 grburgess

I'm not sure I know the answer to either of your questions. The laptop is not a personal laptop but was issued to me by my employer. As I recall it came with Python 2.7, while I later installed Python 3. I've attempted to run my code both through my normal means (building from Sublime Text Editor) and also through command line execution. Both failed.

I will note that last summer (roughly July, possibly August) I was able to run PMN on this laptop. However enough time has passed since then that I have no idea how many things could possibly have changed.

Regardless, I have opted to use UltraNest and it is working very well. I'll leave this issue open and I'm willing to continue exploring the issue to solve it, if it would be helpful to others. Otherwise I don't plan to keep working with PMN.

adj-smith avatar May 28 '20 14:05 adj-smith

I encountered a similar issue on macOS because the MultiNest library path was not part of os.environ['DYLD_LIBRARY_PATH'] even though I exported the path to DYLD_LIBRARY_PATH beforehand. Possibly it is related to the fact that I am using pyenv but I am not sure.

The way I could solve it is by adding the path manually at the start of the code that I am running as:

import os
os.environ['DYLD_LIBRARY_PATH'] = '/path/to/MultiNest/lib

tomasstolker avatar Jan 07 '21 11:01 tomasstolker

I just had this same issue. Setting the system env variable did not seem to help even though doing

echo $DYLD_LIBRARY_PATH

gives the correct path so I'm not sure why pymultinest is not finding it.

Adding the line mentioned above, i.e,: os.environ['DYLD_LIBRARY_PATH'] = '/path/to/MultiNest/lib'

finally worked for me but I found I actually had to add it into run.py of the pymultinest source before it finally solved the issue. Adding that line into my own code didn't seem to make a difference either. This doesn't seem to be a great solution, but it's at least working for now.

Note that the demo code worked without the fix, but I was running it from inside the MultiNest directory so I'm guessing that's why (but it made troubleshooting even more confusing!)

I'm using Python 3.7 in a conda environment on MacOS 10.14.5

westjl avatar Jan 22 '21 14:01 westjl

Is this issue still relevant? If not, could you please explain how it was solved?

JohannesBuchner avatar Jul 07 '22 14:07 JohannesBuchner