前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用PyInstaller打包webssh

使用PyInstaller打包webssh

作者头像
kongxx
发布2019-02-26 12:00:20
5960
发布2019-02-26 12:00:20
举报

接前一篇博客,为了使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 来验证。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.01.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 准备测试环境
  • 准备spec文件
  • 打包
  • 运行服务并测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档