From a70623ee430f9f44fdcc84b80a7e800db061d9fa Mon Sep 17 00:00:00 2001 From: sjplimp Date: Mon, 15 Feb 2016 15:30:15 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14592 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- python/install.py | 49 +++++++++++++++++++++++++++++++++++++++-------- python/lammps.py | 16 ++++++++++------ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/python/install.py b/python/install.py index d589ebca33..d733273fe7 100644 --- a/python/install.py +++ b/python/install.py @@ -37,12 +37,45 @@ print "installing lammps.py in Python site-packages dir" os.chdir('../python') # in case invoked via make in src dir +# extract version string from header +fp = open('../src/version.h','r') +txt=fp.read().split('"')[1].split() +verstr=txt[0]+txt[1]+txt[2] +fp.close() + from distutils.core import setup -sys.argv = ["setup.py","install"] # as if had run "python setup.py install" -setup(name = "lammps", - version = "15May15", - author = "Steve Plimpton", - author_email = "sjplimp@sandia.gov", - url = "http://lammps.sandia.gov", - description = "LAMMPS molecular dynamics library", - py_modules = ["lammps"]) +from distutils.sysconfig import get_python_lib +import site +tryuser=False + +try: + sys.argv = ["setup.py","install"] # as if had run "python setup.py install" + setup(name = "lammps", + version = verstr, + author = "Steve Plimpton", + author_email = "sjplimp@sandia.gov", + url = "http://lammps.sandia.gov", + description = "LAMMPS molecular dynamics library", + py_modules = ["lammps"], + data_files = [(get_python_lib(), ["../src/liblammps.so"])]) +except: + tryuser=True + print "Installation into global site-packages dir failed.\nTrying user site dir %s now." % site.USER_SITE + + +if tryuser: + try: + sys.argv = ["setup.py","install","--user"] # as if had run "python setup.py install --user" + setup(name = "lammps", + version = verstr, + author = "Steve Plimpton", + author_email = "sjplimp@sandia.gov", + url = "http://lammps.sandia.gov", + description = "LAMMPS molecular dynamics library", + py_modules = ["lammps"], + data_files = [(site.USER_SITE, ["../src/liblammps.so"])]) + except: + print "Installation into user site package dir failed.\nGo to ../python and install manually." + + + diff --git a/python/lammps.py b/python/lammps.py index 1db2747247..c6a4b6168e 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -39,17 +39,21 @@ class lammps: modpath = dirname(abspath(getsourcefile(lambda:0))) - # load liblammps.so by default - # if name = "g++", load liblammps_g++.so + # load liblammps.so unless name is given. + # e.g. if name = "g++", load liblammps_g++.so + # try loading the LAMMPS shared object from the location + # of lammps.py with an absolute path (so that LD_LIBRARY_PATH + # does not need to be set for regular installations. + # fall back to loading with a relative path, which typically + # requires LD_LIBRARY_PATH to be set appropriately. try: if not name: self.lib = CDLL(join(modpath,"liblammps.so"),RTLD_GLOBAL) else: self.lib = CDLL(join(modpath,"liblammps_%s.so" % name),RTLD_GLOBAL) except: - type,value,tb = sys.exc_info() - traceback.print_exception(type,value,tb) - raise OSError,"Could not load LAMMPS dynamic library from %s" % modpath - + if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL) + else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL) + # if no ptr provided, create an instance of LAMMPS # don't know how to pass an MPI communicator from PyPar # but we can pass an MPI communicator from mpi4py v2.0.0 and later