Get PyInstaller to import Basemap

后端 未结 2 1951
囚心锁ツ
囚心锁ツ 2021-02-11 04:39

I\'m working on building a standalone executable for a simple tool I built that uses Basemap. (Using Python 2.7, using the dev version of PyInstaller - 2.1). The .exe (single

2条回答
  •  忘掉有多难
    2021-02-11 05:21

    All you need to do is tell PyInstaller to add the basemap data to the distribution. Here is some sample code. Assuming that you have an ortho.py file in directory E:\scratch, put the following ortho.spec in the same directory and run it as

    PyInstaller -y ortho.spec
    

    Here is ortho.spec:

    a = Analysis(['ortho.py'],
                 pathex=['E:\\scratch'],
                 hiddenimports=[],
                 hookspath=None,
                 runtime_hooks=None)
    pyz = PYZ(a.pure)
    exe = EXE(pyz,
              a.scripts,
              exclude_binaries=True,
              name='ortho.exe',
              debug=False,
              strip=None,
              upx=True,
              console=True )
    
    import mpl_toolkits.basemap
    import os
    
    src_basedata = os.path.join(mpl_toolkits.basemap.__path__[0], "data")
    tgt_basedata = os.path.join('mpl_toolkits', 'basemap', 'data')
    
    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas + Tree(src_basedata, prefix=tgt_basedata),
                   strip=None,
                   upx=True,
                   name='ortho')
    

提交回复
热议问题