[lammps-users] Question for running python example in lammps.

Hi,

I compile lammps as shared lib and try to test running example files in python/example. However, there is an error message:

Traceback (most recent call last):

File “mc.py”, line 31, in

lmp = lammps()

File “/opt/anaconda3/lib/python3.8/site-packages/lammps/core.py”, line 144, in init

self.lib = CDLL(libpath,RTLD_GLOBAL)

File “/opt/anaconda3/lib/python3.8/ctypes/init.py”, line 381, in init

self._handle = _dlopen(self._name, mode)

OSError: dlopen(liblammps.dylib, 10): image not found

Is there anything I missed to compile python in lammps? Thanks for any help.

Best,

WJ

What is your LAMMPS version and how exactly did you compile/install LAMMPS?

If you follow the instructions in the manual correctly, it will work. The error message suggests that you did not.
We are testing this regularly on multiple platforms (including MacOS) after every update of the sources.
But since nobody here can read minds (neither those of people nor those of computers), please describe every step you did.

The lammps version I am using is the newest one. The Makefile I used is openmpi_gcc. In the Src directory, I used command” make mode=shared openmpi_gcc” and “make install-python”. After that, I tried import lammps in python environment, it works. But when I tried to run some example files in python directory, error shown as I described.

Thanks for your help.

WJ

Can you please treat this a bit more seriously like you would any other (research project)? also let me remind you, again, that I don’t see what you are doing. However precise information is needed to reproduce and retrace your steps to be able to tell where you went wrong.

The lammps version I am using is the newest one.

That is a very imprecise and unscientific description. “the newest” depends on the day when somebody is reading it and thus would mean something else to somebody looking up my answers in the mailing list archives next month (or next year). also there are always at least three different “newest” versions, the “develop” branch of the git repository, the “newest” patch release and the “newest” stable release. How to determine the version is also prominently explained in the manual: https://docs.lammps.org/Manual_version.html

The Makefile I used is openmpi_gcc.

There is no such makefile in the LAMMPS distribution.

In the Src directory, I used command” make mode=shared openmpi_gcc”

Because there is not openmpi_gcc you should not have compiled LAMMPS as a shared library, but instead should have received an error message.
It is important that you carefully observe and report your observations (again, standard scientific procedure, i.e. something that you should know well).

and “make install-python”.

again, since you apparently didn’t compile a shared library, there should have been an error.

After that, I tried import lammps in python environment, it works. But when I tried to run some example files in python directory, error shown as I described.

which means, that you must done some other (random?) steps, because the import should have failed completely and not produce the error you are reporting.

Thanks for your help.

because your information is incomplete, vague, inaccurate, and unreliable, there is next to nothing that I can do here. for people that have so little experience with compiling software and making so many errors, we generally recommend to install CMake and follow the CMake based build instructions instead.

axel.

axel.