简体   繁体   English

py2app问题

[英]Py2app problems

I have created a python script that uses a tkinter GUI, I have tried to package it using py2app, My problem is that i dont know how to include the tkinter module. 我创建了一个使用tkinter GUI的python脚本,我尝试使用py2app打包它,我的问题是我不知道如何包括tkinter模块。 I have tried packaging my script without the module but all i get is a console message saying "ImportError: no module named tkinter" 我已经尝试将脚本打包而不包含模块,但是我得到的只是一条控制台消息,提示“ ImportError:没有名为tkinter的模块”

To bundle the app I'm assuming you put this in the terminal: 为了捆绑该应用程序,我假设您将其放在终端中:

$ python setup.py py2app

I also had the same problem and have been ransacking the internet searching for a solution. 我也遇到了同样的问题,一直在互联网上搜索解决方案。 I am also running python 3.3 on a mac. 我也在Mac上运行python 3.3。 After I put this: 在我把这个:

$ python3 setup.py py2app

it worked like a charm! 它就像一个魅力! Hope this helps! 希望这可以帮助!

The following setup.py script should do the trick for a basic Tkinter based script (replace 'hello.py' by the name of the actual script). 下面的setup.py脚本应该为基于Tkinter的基本脚本解决问题(用实际脚本的名称替换“ hello.py”)。

from setuptools import setup

setup(
    app=['hello.py'],
    setup_requires=["py2app"],
)

This is the setup.py script from py2app's hello_tk example 这是py2app的hello_tk示例中的setup.py脚本

UPDATE: 更新:

You mention later on that tkinter cannot be imported from "outside" the py2app'd application either, and that the _tkinter extension (_tkinter.so) doesn't exist. 您稍后会提到,tkinter也不能从py2app应用程序的“外部”导入,并且_tkinter扩展名(_tkinter.so)不存在。 That means that something is wrong with your installation of Python 3.3. 这意味着您安装的Python 3.3出了点问题。

one way to package the app is running this command: 打包应用程序的一种方法是运行以下命令:

    py2applet --make-setup filename.py

Then, you can run: 然后,您可以运行:

    python3 setup.py py2app -A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM