import ctypes
import numpy as np
import os

__all__ = ['square']

lib = ctypes.cdll.LoadLibrary("libfoo.so")
lib.square.restype = ctypes.c_int
lib.square.argtypes = [ctypes.c_int]


def square(value):
    """
    Parameters
    ----------
    value: int

    Returns
    --------
    value square
    """
    return lib.square(value)


import ctypes
import numpy as np
import os
import sys

__all__ = ['square']

_path = os.path.dirname(__file__)

libname = None
if sys.platform.startswith('linux'):
	libname = 'libfoo.so'
elif sys.platform == 'darwin':
	libname = 'libfoo.dylib'
elif sys.platform.startswith('win'):
	libname = 'foo.dll'
if libname ==None:
	print("Unknow platform", sys.platform) 
	
else:
	lib = ctypes.CDLL(libname)

	lib.square.restype = ctypes.c_int
	lib.square.argtypes = [ctypes.c_int]


	def square(value):
		"""
		Parameters
		----------
		value: int

		Returns
		--------
		value square
		"""
		return lib.square(value)

Change to cmake to 3.4 and test sys.platform to choose lib extension to resolve import error on MacOSX
Change to cmake to 3.4 and test sys.platform to choose lib extension to resolve import error on MacOSX

  import ctypes
  import numpy as np
  import os
+ import sys
  
  __all__ = ['square']
  
- lib = ctypes.cdll.LoadLibrary("libfoo.so")
+ _path = os.path.dirname(__file__)
+ 
+ libname = None
+ if sys.platform.startswith('linux'):
+ 	libname = 'libfoo.so'
+ elif sys.platform == 'darwin':
+ 	libname = 'libfoo.dylib'
+ elif sys.platform.startswith('win'):
+ 	libname = 'foo.dll'
+ if libname ==None:
+ 	print("Unknow platform", sys.platform) 
+ 	
+ else:
+ 	lib = ctypes.CDLL(libname)
+ 
- lib.square.restype = ctypes.c_int
+ 	lib.square.restype = ctypes.c_int
- lib.square.argtypes = [ctypes.c_int]
+ 	lib.square.argtypes = [ctypes.c_int]
  
  
- def square(value):
+ 	def square(value):
-     """
+ 		"""
-     Parameters
+ 		Parameters
-     ----------
+ 		----------
-     value: int
+ 		value: int
  
-     Returns
-     --------
+ 		Returns
+ 		--------
-     value square
+ 		value square
-     """
+ 		"""
-     return lib.square(value)
+ 		return lib.square(value)
  
- 
Change to cmake to 3.4 and test sys.platform to choose lib extension to resolve import error on MacOSX
## Code Before:
import ctypes
import numpy as np
import os

__all__ = ['square']

lib = ctypes.cdll.LoadLibrary("libfoo.so")
lib.square.restype = ctypes.c_int
lib.square.argtypes = [ctypes.c_int]


def square(value):
    """
    Parameters
    ----------
    value: int

    Returns
    --------
    value square
    """
    return lib.square(value)


## Instruction:
Change to cmake to 3.4 and test sys.platform to choose lib extension to resolve import error on MacOSX
## Code After:
import ctypes
import numpy as np
import os
import sys

__all__ = ['square']

_path = os.path.dirname(__file__)

libname = None
if sys.platform.startswith('linux'):
	libname = 'libfoo.so'
elif sys.platform == 'darwin':
	libname = 'libfoo.dylib'
elif sys.platform.startswith('win'):
	libname = 'foo.dll'
if libname ==None:
	print("Unknow platform", sys.platform) 
	
else:
	lib = ctypes.CDLL(libname)

	lib.square.restype = ctypes.c_int
	lib.square.argtypes = [ctypes.c_int]


	def square(value):
		"""
		Parameters
		----------
		value: int

		Returns
		--------
		value square
		"""
		return lib.square(value)
