Run python files using lammps

Dear All, I am trying to run a python file inside the lammps running file. I also build the lammps using the python package.

here is the command that I am running in lammps running file:

python source pycode.py

and I have simple test python code pycode.py:
print (“hello”)

But I am getting an error below.

LAMMPS (23 Jun 2022 - Update 2)
OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98)
using 1 OpenMP thread(s) per MPI task
ERROR: Invalid python command (src/PYTHON/python_impl.cpp:196)
Last command: python source pycode.py

Can anyone help me how can I run a python code properly.

Best regards
Saeed

You are using a syntax that is described in the online manual. But that very syntax was introduced only in the 22Dec2022 version of LAMMPS. Note the “Changed in version” tag. You have to either follow the documentation that corresponds to your (older) version of LAMMPS or upgrade to the latest release (2 August 2023).

With the current version, your input executes as expected:

$ ./lammps-shell 
LAMMPS Shell version 1.2  OS: Linux "Fedora Linux 38 (Thirty Eight)" 6.4.7-200.fc38.x86_64 x86_64
GNU C++ 13.2.1 20230728 (Red Hat 13.2.1-1) with OpenMP 4.5
LAMMPS (2 Aug 2023 - Development - patch_2Aug2023-123-gab4ae4f177)
  using 8 OpenMP thread(s) per MPI task
LAMMPS Shell> python source pycode.py
Hello, World!
LAMMPS Shell> 
Total wall time: 0:00:03

I am looking at the documentation for your version of LAMMPS and it seems that the “source” keyword may have be broken in that version altogether.