Trouble with installing pylammps on Windows 10

Hi LAMMPS developers & users.

I’m trying to install the lammps wrapper on Windows 10. I downloaded and installed LAMMPS-64bit-Python-stable-MSMPI. I can import lammps in the conda environment. But when I executed lmps = lammps.lammps(), I was given the error

FileNotFoundError: Could not find module ‘E:\LAMMPS 64-bit 2Aug2023-MSMPI with Python\bin\liblammps.dll’ (or one of its dependencies). Try using the full path with constructor syntax.

The following was added to the environment variables automatically during installation:

  • E:\LAMMPS 64-bit 2Aug2023-MSMPI with Python\Python to PYTHONPATH;
  • E:\LAMMPS 64-bit 2Aug2023-MSMPI with Python\bin to path.
  • image

I tried to use Python 3.8 or Python 3.11 for lammps wrapper. Neither of them worked.

Any comment or advice is welcome. Thanks in advance!

Useful information is summarized below:

  • System: Windows 10.
  • LAMMPS: 64-bit 2Aug2023-MSMPI
  • Python: 3.8 or 3.11

Error snapshot:

You need to understand that there are two independent ways to connect Python with LAMMPS:

  1. there is the “lammps” Python module which allows to call LAMMPS from Python
  2. there is the “PYTHON” package in LAMMPS that allows to call Python from LAMMPS (e.g. to write pair styles or fixes in Python instead of C++).

For the first option, you can use any of the LAMMPS installer packages.

The “with Python” installer packages are for the second case only. In this case, LAMMPS must be compiled and linked with a specific Python version and thus this specific Python installation must be bundled with LAMMPS. You cannot use any other Python installation (e.g. via conda) with this. The error you are seeing would then come from trying to load the wrong and incompatible Python library.
The error message you report is consistent with that: liblammps.dll is found (as needed by the LAMMPS Python module), but one or more dependencies are missing, and that could come from a mismatch between the Python runtime version included in LAMMPS and your conda installation.

It seems that you want to use the first method but want to use your Python installation. In that case you must not use a “with Python” installer package.

In addition you need to check, if your LAMMPS version is functional as a standalone version. For that you can just type “lmp -h” in the Command Prompt window and it should display information about the specific LAMMPS executable without generating an error.

If you want to use both LAMMPS-Python interfaces with a custom Python installation, you need to compile LAMMPS yourself from source. It is not possible to pre-compile a matching LAMMPS package for that case.

1 Like

I switched from LAMMPS-64bit-Python-stable-MSMPI to LAMMPS-64bit-stable-MSMPI just now. And I can use lammps python module normally.

You’re my lifesaver. Thanks a million!!!