V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
solomaster
V2EX  ›  Python

有哪一种轮子可以实现 跨平台的桌面应用并且对应平台不用安装 Python 库?

  •  
  •   solomaster · 2017-07-22 18:19:54 +08:00 · 3542 次点击
    这是一个创建于 2469 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用 python 做桌面应用,想实现在 windows 下就是一个 exe,点击就可以运行 UI 界面。在 mac 下就是一个 app 同样点击就可以运行。不要求对应平台安装 python 库。python 新手,求教。
    12 条回复    2017-07-24 11:34:04 +08:00
    haozhang
        1
    haozhang  
       2017-07-22 18:33:54 +08:00 via iPhone
    eletrcon
    Cooky
        2
    Cooky  
       2017-07-22 18:34:32 +08:00 via Android
    qt
    muyi
        3
    muyi  
       2017-07-22 18:56:33 +08:00 via iPhone   ❤️ 1
    delphi
    fearme
        4
    fearme  
       2017-07-22 18:59:07 +08:00 via iPhone
    @muyi Delphi 调用 python 方便吗
    CryMeatel
        5
    CryMeatel  
       2017-07-22 19:00:25 +08:00 via Android   ❤️ 1
    LZ 的意思应该是不用重新安装 Python 环境吧?

    开发机上选一种 GUI 包安装,开发好,然后用 PyIstaller 打包成一个 exe。然后就可以拿着这一个 exe 到处跑了
    xieranmaya
        6
    xieranmaya  
       2017-07-22 20:40:53 +08:00
    现在必然是 Electorn
    chenstack
        7
    chenstack  
       2017-07-22 21:22:14 +08:00   ❤️ 1
    最近我在写一个自用小工具时用了 embed python 的方案,C++端用了[pybind11]( https://github.com/pybind/pybind11) 和 wxWidgets,pybind11 好处是用模板元编程封装好了 python C API 调用,很适合面向对象。[项目地址在这]( https://github.com/czastack/wxFEFactory) ,希望对 LZ 有帮助,还没时间把 GUI 部分单独抽取出来,也没写文档,有 C++基础的话直接看看源码。这个项目还在开发中,也只在 VS 下测试过,可能有些内存泄漏的问题,但可以提供个思路,PS: 很多想法有参考 Sublime Text。
    编译后 C++是主体,在里面初始化好 python 环境,再调用一个外部 python 文件作为入口。python 可以用 dll 方式链接,像 sublime text 那样,也可以静态链接到主程序里。用这个方案的原因是 Electorn, qt 这样方案对我来说略大,pyqt, wxPython 同理,且之前我用 wxPython Phoenix 的 wxPropertyGrid 有 crash 的情况,最后决定自己折腾,用 C++封装,release 编译后全部内容能控制在 6M 左右。其中还仿照 RN 的写法,用字典存放样式,现在只实现了几个简单的样式。

    python 中调用类似这样
    ```python
    class MainFrame:
    def __init__(self):
    self.render()
    if hasattr(app, 'project'):
    self.onOpenProject(app.project)

    def render(self):
    with ui.MenuBar() as menubar:
    with ui.Menu("文件"):
    with ui.Menu("新建"):
    ui.MenuItem("新建工程\tCtrl+Shift+N", onselect=self.newProject)
    ui.MenuItem("退出\tCtrl+Q", onselect=self.closeWindow)
    with ui.Menu("视图"):
    ui.MenuItem("切换控制台\tCtrl+`", onselect=self.toggleConsole)

    with ui.Window("火纹工厂", style=winstyle, styles=styles, menuBar=menubar) as win:
    with ui.AuiManager(key="aui"):
    ui.AuiItem(ui.ToolBar().addTool("123", "1234", "", self.onselect).realize(), direction="top", captionVisible=False)
    ui.AuiItem(ui.ListBox(options=modules, values=lambda x: x, onselect=self.onNav), captionVisible=False)
    ui.AuiItem(ui.AuiNotebook(key="book"), direction="center", maximizeButton=True, captionVisible=False)


    winstyle = {
    'width': 1200,
    'height': 960,
    }

    styles = {
    'type': {

    },
    'class': {
    'fill': {'flex': 1},
    'expand': {'expand': True},
    'console-input': {
    'expand': True,
    'flex': 1,
    },
    'console-input-multi': {'height': 70},
    'btn-sm': {'width': 30,}
    }
    }
    ```
    效果如下
    ![效果]( http://othrhighg.bkt.clouddn.com/20170722202216.png)
    miao1007
        8
    miao1007  
       2017-07-22 21:24:03 +08:00 via Android
    flash
    charli
        9
    charli  
       2017-07-23 09:00:16 +08:00
    打包行了
    ivechan
        10
    ivechan  
       2017-07-23 15:28:02 +08:00
    轻量级还是用 qt 吧,毕竟 "electron is flash for the desktop".
    XIVN1987
        11
    XIVN1987  
       2017-07-23 20:54:17 +08:00 via Android
    用 pyqt 开发,然后用 pyinstaller 打包成单文件、免安装.exe 可执行文件,,除了体积比较大、启动速度不如.py 直接运行外其他都挺好
    CryMeatel
        12
    CryMeatel  
       2017-07-24 11:34:04 +08:00
    补充下,PyIstaller 也可以同一份代码打成 exe, linux 的 elf, mac 的格式等
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1031 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:34 · PVG 03:34 · LAX 12:34 · JFK 15:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.