我有一个tkinter应用程序,我想分发给没有安装python的同事。我将py2app与以下setup.py文件一起使用
from setuptools import setup
import sys
sys.setrecursionlimit(5000)
#APP would be the name of the file your code is in.
APP = ['Doughnut_stress.py']
DATA_FILES = ['C20.icns']
#The Magic is in OPTIONS.
OPTIONS = {
'packages': ['tkinter', 'matplotlib'],
'includes': ['tkinter'],
'argv_emulation': False,
'iconfile': 'C20.icns', #change app.icns to the image file name!!!
'plist': {
'CFBundleName': 'Axial bearing program',
'CFBundleDisplayName': 'Axial bearing program',
'CFBundleGetInfoString': "Calculates C20 axial bearing",
'CFBundleVersion': "0.0.0",
'CFBundleShortVersionString': "0.0.0",
'NSHumanReadableCopyright': u"Copyright © 2020, Component 2.0 A/S, All Rights Reserved"
}
}
setup(
app=APP,
name='Axial bearing program', #change to anything
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
然后我用
python setup.py py2app
将该程序编译为应用程序。注意我已经将python符号链接到python3。我的python 3版本为3.7.5,并通过MacPorts安装。py2app的版本为0.20,tkinter的版本为8.6
该程序可以很好地编译,我可以从终端运行它,或者只需双击应用程序文件,它就会按预期运行。
但是,当我将其发送给我的同事并尝试通过双击该应用程序从他的计算机上打开它时,会弹出一个对话框,我可以选择“打开控制台”或“终止”。如果我通过终端运行程序(通过运行APP_NAME.app/Contents/MacOS/APP_NAME),则会出现以下错误
Traceback (most recent call last):
File "/Users/prm/Downloads/Component 2.0 axial bearing program.app/Contents/Resources/__boot__.py", line 416, in <module>
_run()
File "/Users/prm/Downloads/Component 2.0 axial bearing program.app/Contents/Resources/__boot__.py", line 394, in _run
exec(compile(source, path, "exec"), globals(), globals())
File "/Users/prm/Downloads/Component 2.0 axial bearing program.app/Contents/Resources/Doughnut_stress.py", line 31, in <module>
root = Tk()
File "tkinter/__init__.pyc", line 2023, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
/opt/local/lib/tcl8.6 {/Users/prm/Downloads/Component 2.0 axial bearing program.app/Contents/lib/tcl8.6} {/Users/prm/Downloads/Component 2.0 axial bearing program.app/lib/tcl8.6} {/Users/prm/Downloads/Component 2.0 axial bearing program.app/Contents/library} {/Users/prm/Downloads/Component 2.0 axial bearing program.app/library} {/Users/prm/Downloads/Component 2.0 axial bearing program.app/tcl8.6.9/library} /Users/prm/Downloads/tcl8.6.9/library
This probably means that Tcl wasn't installed properly.
2020-01-20 15:54:28.439 Component 2.0 axial bearing program[34251:2906750] Component 2.0 axial bearing program Error
我还可以在APP_NAME.app/Contents/MacOS/python中运行包含的python文件,这会产生此错误
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000000010d0f8dc0 (most recent call first):
Abort trap: 6
之前有人在Reddit上发布了有关此内容的消息,但没有答案https://www.reddit.com/r/learnpython/comments/c1on6f/py2app_in_a_mac_without_python/
如何解决此问题,以便分发我的python应用程序?
在我的设置中,同样的问题(缺少init.tcl):
手动复制后:
- /Library/Frameworks/Python.framework/Versions/3.7/lib/tcl8
- /Library/Frameworks/Python.framework/Versions/3.7/lib/tcl8.6
- /Library/Frameworks/Python.framework/Versions/3.7/lib/tk8.6
至
- path_to_venv/lib
py2app将从那里获取它,并将其存储在以下位置的.app中:
- path_to_project/dist/myApp.app/Contents/Resources/lib/
然后从这里通过python代码找到
我看到2个主要选项如何使其自动化:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句