1

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
)
halfer
  • 19,824
  • 17
  • 99
  • 186
Dániel Terbe
  • 105
  • 1
  • 10
  • Try combining the two lines into one that reads: `library_dirs=[libdirs,epre+libdirs[0],epre+libdirs[1]],` ... might be the right thing to do, might not. In any event, commenting it out seems like it worked but the version comparison is failing. What does the code look like that reports the "... do not match..." error? – par Sep 16 '15 at 07:24
  • If you need to set this up quickly, you could always use Vagrant or a VirtualBox Linux machine - maybe it is better tested on Linux? – halfer Sep 16 '15 at 08:59
  • @par I get the same error (second) using your suggestion. The code looks like this: – Dániel Terbe Sep 16 '15 at 10:35
  • @halfer Yes, in theory it works on linux, but it wouldn't be sufficient to run virtual machine. But I'll do if nothing works. – Dániel Terbe Sep 16 '15 at 10:42

1 Answers1

0

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.

Christoph W.
  • 958
  • 2
  • 10
  • 24
  • I used another installation guide, and I think I followed all points only this setup.py step fails. I tried what you've linked but the port python27 does not work right at the start: 'sudo port install python27 py27-numpy py27-scipy py27-matplotlib py27-ipython Password: Error: Port python27 not found' . Btw I found out others had the same problem in mac (older system) but when they commented out the line it worked for them. (http://www.neuron.yale.edu/phpBB/viewtopic.php?f=4&t=2692&start=15) There is no pip quick install for neuron. – Dániel Terbe Sep 16 '15 at 12:10