美文网首页
使用PyInstaller打包webssh

使用PyInstaller打包webssh

作者: kongxx | 来源:发表于2019-01-25 21:23 被阅读14次

    接前一篇博客,为了使webssh更容易安装部署,我在想是不是可以把webssh打包成一个独立的可执行文件,这样使用起来不是更方便呢。于是乎我想到了是不是可以使用PyInstaller来打包。

    准备测试环境

    这一步主要是准备一个干净的virtualenv环境,并安装pyinstaller和webssh。

    $ cd ~
    $ virtualenv myenv
    $ cd myenv
    $ . bin/activate
    $ pip install pyinstaller
    $ pip install webssh
    

    准备spec文件

    为了使用pyinstaller,需要准备一个spec文件并保存为 “~/myenv/lib/python2.7/site-packages/webssh/wssh.spec”,内容如下:

    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(['main.py'],
                 pathex=['webssh'],
                 binaries=[],
                 datas=[
                  ('static', 'webssh/static'),
                  ('templates', 'webssh/templates')
                 ],
                 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='wssh',
              debug=False,
              strip=False,
              upx=True,
              runtime_tmpdir=None,
              console=True )
    

    打包

    $ cd ~/myenv/lib/python2.7/site-packages/webssh/
    $ pyinstaller wssh.spec
    

    运行服务并测试

    $ dist/wssh --port=12345
    

    然后通过浏览器访问 http://<ip>:12345 来验证。

    相关文章

      网友评论

          本文标题:使用PyInstaller打包webssh

          本文链接:https://www.haomeiwen.com/subject/funvjqtx.html