How to bundle a python script that imports zerorpc with pyinstaller?

I have the following script called api.py that I’d like to turn into a python app using pyinstaller.

The below function works when I run it out of sublime text but when I try to convert it into an unix executable application using pyinstaller, the app does not work. Pyinstaller works only if I dont import zerorpc.

api.py

import zerorpc

class CalcApi(object): 
    def echo(self, text):
        return text

def main():
    addr = 'tcp://127.0.0.1:4242'
    s = zerorpc.Server(CalcApi())
    s.bind(addr)
    s.run()

if __name__ == '__main__':
    main()

After running the following command I get the below error:

pyinstaller api.py -F

Error after double clicking on the unix executable

Traceback (most recent call last):
  File "api.py", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zerorpc/__init__.py", line 29, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zerorpc/context.py", line 32, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zerorpc/gevent_zmq.py", line 28, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zmq/__init__.py", line 34, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zmq/backend/__init__.py", line 40, in <module>
  File "site-packages/zmq/backend/__init__.py", line 27, in <module>
  File "site-packages/zmq/backend/select.py", line 26, in select_backend
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/zmq/backend/cython/__init__.py", line 6, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 687, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: dlopen(/var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so, 2): Symbol not found: _zmq_errno
  Referenced from: /var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so
  Expected in: flat namespace
 in /var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so
[914] Failed to execute script api
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

Also, this is the log after running pyinstaller api.py

59 INFO: PyInstaller: 3.3.1
59 INFO: Python: 2.7.13
65 INFO: Platform: Darwin-15.6.0-x86_64-i386-64bit
65 INFO: wrote /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/api.spec
72 INFO: UPX is not available.
73 INFO: Extending PYTHONPATH with paths
['/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test',
 '/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test']
73 INFO: checking Analysis
73 INFO: Building Analysis because out00-Analysis.toc is non existent
73 INFO: Initializing module dependency graph...
75 INFO: Initializing module graph hooks...
130 INFO: running Analysis out00-Analysis.toc
140 INFO: Caching module hooks...
146 INFO: Analyzing /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/api.py
3237 INFO: Processing pre-safe import module hook   _xmlplus
3370 INFO: Processing pre-find module path hook   distutils
5111 INFO: Processing pre-find module path hook   site
5111 INFO: site: retargeting to fake-dir '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/fake-modules'
6135 INFO: Loading module hooks...
6136 INFO: Loading module hook "hook-distutils.py"...
6137 INFO: Loading module hook "hook-sysconfig.py"...
6137 INFO: Loading module hook "hook-xml.py"...
6201 INFO: Loading module hook "hook-zmq.py"...
6518 INFO: Excluding import 'zmq.libzmq'
6519 INFO:   Removing import of zmq.libzmq from module zmq
6520 INFO: Loading module hook "hook-pycparser.py"...
6717 INFO: Loading module hook "hook-httplib.py"...
6719 INFO: Loading module hook "hook-encodings.py"...
7148 INFO: Loading module hook "hook-_tkinter.py"...
7153 INFO: checking Tree
7154 INFO: Building Tree because out00-Tree.toc is non existent
7154 INFO: Building Tree out00-Tree.toc
7206 INFO: checking Tree
7206 INFO: Building Tree because out01-Tree.toc is non existent
7206 INFO: Building Tree out01-Tree.toc
7228 INFO: Loading module hook "hook-pkg_resources.py"...
7451 INFO: Processing pre-safe import module hook   win32com
7654 INFO: Loading module hook "hook-gevent.monkey.py"...
7662 INFO: Loading module hook "hook-setuptools.py"...
10546 INFO: Loading module hook "hook-numpy.core.py"...
10663 INFO: Loading module hook "hook-pydoc.py"...
10665 INFO: Excluding import 'Tkinter'
10666 INFO:   Removing import of Tkinter from module pydoc
10686 INFO: Looking for ctypes DLLs
10736 INFO: Analyzing run-time hooks ...
10741 INFO: Including run-time hook 'pyi_rth__tkinter.py'
10745 INFO: Including run-time hook 'pyi_rth_pkgres.py'
10748 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
10761 INFO: Looking for dynamic libraries
11059 INFO: Looking for eggs
11059 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/2.7/Python
11065 INFO: Warnings written to /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/warnapi.txt
11114 INFO: Graph cross-reference written to /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/xref-api.html
11330 INFO: checking PYZ
11330 INFO: Building PYZ because out00-PYZ.toc is non existent
11330 INFO: Building PYZ (ZlibArchive) /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/out00-PYZ.pyz
12109 INFO: Building PYZ (ZlibArchive) /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/out00-PYZ.pyz completed successfully.
12255 INFO: checking PKG
12255 INFO: Building PKG because out00-PKG.toc is non existent
12255 INFO: Building PKG (CArchive) out00-PKG.pkg
18776 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18852 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
18852 INFO: checking EXE
18852 INFO: Building EXE because out00-EXE.toc is non existent
18852 INFO: Building EXE from out00-EXE.toc
18852 INFO: Appending archive to EXE /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/dist/api
18874 INFO: Fixing EXE for code signing /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/dist/api
18878 INFO: Building EXE from out00-EXE.toc completed successfully

Also this is my api.spec file

# -*- mode: python -*-

block_cipher = None


a = Analysis(['api.py'],
             pathex=['/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='api',
          debug=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

I’ve reinstalled everything and upgraded all packages including zerorpc and pyinstaller to no avail

How to bundle a python script that imports zerorpc with pyinstaller?