Installing python wrapper for LAMMPS

Hello! I am trying to install LAMMPS on a Mac using the macOS terminal. I followed the instructions on and built the program using the Cmake commands on 3.1. Build LAMMPS with CMake — LAMMPS documentation . After that I followed the PyLammps quick start tutorial (8.6.3. PyLammps Tutorial — LAMMPS documentation) to build the shared folder and open the PyLammps Jupyter notebooks. However, when I run one of the jupyter notebooks, I get an import error saying there is ‘no module named Lammps’.

The errors seem to be related to the following:

  • sys.path is missing some paths
  • ld is missing some paths
  • run command seems to fail and possible can’t find the path to the lmp command

I have been able to import LAMMPS by appending a path to sys.path, but that leads to further errors running the files, all seem related to the file locations. I have tried adding the export commands (from 2.2. Installation — LAMMPS documentation):



export PATH=$HOME/.local/bin:$PATH

Is there any command in the installation I may have missed out, or any reason why I am having so many path errors? Thank you!!!

(EDIT) the commands used for installation are as follows:

Dowloaded from


unzip and untar

tar -xzvf lammps-stable.tar.gz

build LAMMPS with CMake

#go to main LAMMPS directory
mkdir build
cd build
cmake …/cmake
cmake --build .
make install

build shared library for PyLammps

#first return to main LAMMPS directory
cd …
mkdir build-shared
cd build-shared
cmake . -DPYTHON_EXECUTABLE=$(which python)
make install-python

create virtualenv named ‘pyenv’

virtualenv $HOME/python/pyenv
source $HOME/python/pyenv/bin/activate
(testing) make install-python
(testing) pip install matplotlib jupyter mpi4py

error message in terminal

source $HOME/python/pyenv/bin/activate
(pyenv) python3
Python 3.10.2 (main, Feb 2 2022, 06:19:27) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
(pyenv) import lammps
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘lammps’

  • you didn’t say which version of LAMMPS you are trying to install. that is crucial information.
  • Lammps != lammps
  • rather than quoting the links to the documentation that you followed, you should list the commands that you actually typed and executed. lots of people that encounter problems do so because they didn’t follow the documentation correctly or had typos

these questions are impossible to answer because you didn’t provide sufficient information

Thank you so much for your response. I am clearly new to this forum, and I appreciate the advice. I have updated my post to include the commands I used for the installation. Please let me know if there is any other information I should provide. Thanks!

I see one major problem: the virtual environment must be created and activated before configuring LAMMPS for building with shared libs. Otherwise the installation of the LAMMPS python module will be in the default “user” folder of the global python environment and thus not visible within the virtual environment. re-running make install-python does not work in that case.

Furthermore, the first compilation step with CMake step is superfluous and can be omitted as is the -DBUILD_LIB=yes flag. Without that setting environment variables doesn’t make sense. The installation done by make install-python is supposed to install the module in such a way that no environment variables should be needed.

Thank you so much, akohlmey! I really appreciate the help. I’ve made the changes you suggested, and I can now load lammps in the virtual environment!

I’ve tried running the example jupyter notebooks provided by PyLammps, but there still seem to be environmental variable issues. I’ve included screenshots of the dihedral jupyter notebook example below. Is the error also related to the installation process?

Not likely. It would be failing at earlier commands. This may be (yet another) issue caused by the idiosyncrasies of the MacOS operating system (Apple software engineers seem to enjoy breaking cross-platform applications). This is beyond my experience (I don’t use a Mac locally and don’t use LAMMPS in jupyter notebooks but from the console). Perhaps @rberger has some ideas?

I figured it out. I needed to add the lammps environment into anaconda. I ran the command: conda install -c conda-forge lammps. It seems to be working now. Thank you so much for your help!!!

With that command you installed another copy of LAMMPS through yet a different method.
Mind you that the anaconda path of installing LAMMPS is not provided and supported by the LAMMPS developers, so you need to direct all future questions to those people that contributed this.