简体   繁体   中英

Setup.py installation file on mac

I would like to install a module for python (neuron) but the script is not working on mac OS X.

First I tried I got this massage:

tittorento:nrnpython Dani$ python setup.py install --with-nrnpython=dynamic
  File "setup.py", line 79
    = [ epre+libdirs[0],epre+libdirs[1] ],
    ^
SyntaxError: invalid syntax

The corresponding code:

hoc_module = Extension(
      "neuron.hoc",
      ["inithoc.cpp"],
      library_dirs=libdirs,
      = [ epre+libdirs[0],epre+libdirs[1] ],
      #extra_objects = [],
      libraries = [
    "nrnpython",
        "nrnoc", "oc", "nrniv", "ivoc",
        "memacs",
    "meschach", "neuron_gnu",
    "nrnmpi",
        "scopmath", "sparse13", "sundials",
    "readline",
    "IVhines",
      ],
      include_dirs = include_dirs,
      define_macros=defines
    )

If I comment out that line then it says:

tittorento:nrnpython Dani$ python setup.py install --with-nrnpython=dynamic
Error:
NEURON configure time python:   
Python presently executing setup.py: /usr/local/opt/python/bin/python2.7   2.7
These do not match, and they should!

I don't know what to do. I need to set up this module for my scientific work.

The code which gives this error is below:

#setup.py
from distutils.core import setup, Extension
from distutils.sysconfig import get_python_version

import sys
import os

# NRNPYTHON_DEFINES which were enabled at configure time
extern_defines = ""
nrnpython_exec = ""
nrnpython_pyver = ""
nrn_srcdir = "."
build_rx3d = 0
ivlibdir = "/Applications/NEURON-7.3/iv/x86_64/lib"
if ivlibdir == "" :
    ivlibdir = '.'

destdir = os.getenv("DESTDIR")
if not destdir:
  destdir = ""

instdir = destdir + "/Applications/NEURON-7.3/iv"
if nrn_srcdir[0] != '/' :
    nrn_srcdir = '../../' + nrn_srcdir

if nrnpython_pyver!=get_python_version():
    print "Error:"
    print "NEURON configure time python: "+nrnpython_exec+"  "+ nrnpython_pyver
    print "Python presently executing setup.py: "+sys.executable+"   "+ get_python_version()
    print "These do not match, and they should!"
    sys.exit(1)


ldefs = extern_defines.split('-D')

# if using MPI then at least for linking need special paths and libraries
mpicc_bin = "gcc"
mpicxx_bin = "g++"
import os
os.environ["CC"]=mpicc_bin
os.environ["CXX"]=mpicxx_bin

# apparently we do not need the following
#################################
## following http://code.google.com/p/maroonmpi/wiki/Installation
## hack into distutils to replace the compiler in "linker_so" with mpicxx_bin
#
#import distutils
#import distutils.unixccompiler
#
#class MPI_UnixCCompiler(distutils.unixccompiler.UnixCCompiler):
#    __set_executable = distutils.unixccompiler.UnixCCompiler.set_executable
#
#    def set_executable(self,key,value):
#   print "MPI_UnixCCompiler ", key, " | ", value
#        if key == 'linker_so' and type(value) == str:
#            value = mpicxx_bin + ' ' + ' '.join(value.split()[1:])
#
#        return self.__set_executable(key,value)
#    
#distutils.unixccompiler.UnixCCompiler = MPI_UnixCCompiler
#################################

include_dirs = [nrn_srcdir+'/src/oc', '../oc', nrn_srcdir+'/src/nrnmpi']
defines = []

libdirs = [destdir + "/Applications/NEURON-7.3/iv/x86_64/lib",
  ivlibdir
]
epre='-Wl,-R'



hoc_module = Extension(
      "neuron.hoc",
      ["inithoc.cpp"],
      #library_dirs=libdirs,
      #= [ epre+libdirs[0],epre+libdirs[1] ],
      #extra_objects = [],

      libraries = [
    "nrnpython",
        "nrnoc", "oc", "nrniv", "ivoc",
        "memacs",
    "meschach", "neuron_gnu",
    "nrnmpi",
        "scopmath", "sparse13", "sundials",
    "readline",
    "IVhines",
      ],
      include_dirs = include_dirs,
      define_macros=defines
    )

# specify that the data_files paths are relative to same place as python files
# from http://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py
from distutils.command.install import INSTALL_SCHEMES
for scheme in INSTALL_SCHEMES.values():
    scheme['data'] = scheme['purelib']

ext_modules = [hoc_module]
if build_rx3d:
  try:
    import numpy
    # TODO: do we need to use os.path.join?
    src_path = nrn_srcdir + '/share/lib/python/neuron/rxd/geometry3d/'
    build_path = '../../share/lib/python/neuron/rxd/geometry3d/'
    include_dirs = [nrn_srcdir + '/share/lib/python/neuron/rxd/geometry3d', '.', numpy.get_include()]
    ext_modules=[hoc_module,
                   Extension("neuron.rxd.geometry3d.graphicsPrimitives",
                             sources=[build_path + "graphicsPrimitives.cpp"],
                             include_dirs=include_dirs),
                   Extension("neuron.rxd.geometry3d.ctng",
                             sources=[build_path + "ctng.cpp"],
                             include_dirs=include_dirs),
                   Extension("neuron.rxd.geometry3d.surfaces",
                             sources=[build_path + "surfaces.cpp", src_path + "marching_cubes2.c", src_path + "llgramarea.c"],
                             include_dirs=include_dirs)]    
  except:
    pass

packages=['neuron','neuron.neuroml','neuron.tests', 'neuron.rxd']
if build_rx3d:
  packages +=['neuron.rxd.geometry3d']

setup(name="NEURON", version="7.4",
      description = "NEURON bindings for python",
      package_dir = {'':instdir+'/share/nrn/lib/python'},
      packages=packages,
      data_files = [('neuron', [nrn_srcdir + '/share/lib/python/neuron/help_data.dat'])],
      ext_modules=ext_modules
)

I think this installation guide is quite good and works for os x: http://labrigger.com/blog/2012/08/30/getting-neuron-to-run-on-os-x-with-python-support/

Maybe you forgot to build the module before calling the install command?

Edit: I would recommend to use the tool "pip" for installing modules and packages but a post of 2012 says that neuron is not available through "pip" for os x but for windows and linux. This post is three years old so maybe os x is supported now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM