Using python with LAMMPS. I am not able to import a module

Code link

This python script part of lammps tools gives me the following error when I try to run it.

Traceback (most recent call last):
File “/home/prajwal/Documents/lammps-stable/lammps-23Jun2022/tools/python/neb_combine.py”, line 15, in
from dump import dump
ImportError: cannot import name ‘dump’ from ‘dump’ (/home/prajwal/.local/lib/python3.8/site-packages/dump/init.py)

a) you are looking at the wrong LAMMPS github repository. The correct one is at GitHub - lammps/lammps: Public development project of the LAMMPS MD software package
b) you seem to have a python package called “dump” installed in your local python site packages folder which is loaded before the tools/python/pizza/dump.py. To change the behavior the line sys.path.append(path) would need to be changed to sys.path.insert(1,path) or you have to uninstall that dump package.

1 Like

Thank you. I have uninstalled the dump module installed in my local python site package folder and changed sys.path.append(path) to sys.path.insert(1,path). Now I’m getting the following error.

Traceback (most recent call last):
File “/home/prajwal/Documents/lammps-stable/lammps-23Jun2022/tools/python/neb_combine.py”, line 15, in
from dump import dump
ModuleNotFoundError: No module named ‘dump’

Changes made in neb_combine.py
import sys,os
path = os.environ[“LAMMPS_PYTHON_TOOLS”]
sys.path.insert(1,path)
from dump import dump

where LAMMPS_PYTHON_TOOLS directs to /home/prajwal/Documents/lammps-stable/lammps-23Jun2022/tools/python/pizza/dump.py

This is not correct. See the README file.

1 Like

Thank you. It is working now.
I have changed LAMMPS_PYTHON_TOOLS directing path from “/home/prajwal/Documents/lammps-stable/lammps-23Jun2022/tools/python/pizza/dump.py” to “/home/prajwal/Documents/lammps-stable/lammps-23Jun2022/tools/python/pizza”