PyInstaller 应用在 Mac 上无法打开

5

我正在尝试为我编写的程序创建一个应用程序。在Windows上做这个没有问题,但是我已经尝试了一个星期来让OSX版本工作。这是我的终端看起来像什么:

Thomass-iMac:gene_expression Tomallama$ python3 --version
Python 3.6.6
Thomass-iMac:gene_expression Tomallama$ python3 -m PyInstaller -- 
onefile gene_expression.py
190 INFO: PyInstaller: 3.3.1
191 INFO: Python: 3.6.6
196 INFO: Platform: Darwin-15.6.0-x86_64-i386-64bit
197 INFO: wrote 
/Users/Tomallama/Desktop/Programs/gene_expression/gene_expression.spec
200 INFO: UPX is not available.
202 INFO: Extending PYTHONPATH with paths
['/Users/Tomallama/Desktop/Programs/gene_expression',
 '/Users/Tomallama/Desktop/Programs/gene_expression']
202 INFO: checking Analysis
202 INFO: Building Analysis because out00-Analysis.toc is non existent
202 INFO: Initializing module dependency graph...
203 INFO: Initializing module graph hooks...
205 INFO: Analyzing base_library.zip ...
3787 INFO: running Analysis out00-Analysis.toc
3794 INFO: Caching module hooks...
3798 INFO: Analyzing 
/Users/Tomallama/Desktop/Programs/gene_expression/gene_expression.py
4017 INFO: Loading module hooks...
4017 INFO: Loading module hook "hook-_tkinter.py"...
4020 ERROR: Tcl/Tk improperly installed on this system.
4020 INFO: Loading module hook "hook-encodings.py"...
4103 INFO: Loading module hook "hook-pydoc.py"...
4104 INFO: Loading module hook "hook-xml.py"...
4408 INFO: Looking for ctypes DLLs
4408 INFO: Analyzing run-time hooks ...
4411 INFO: Including run-time hook 'pyi_rth__tkinter.py'
4418 INFO: Looking for dynamic libraries
4510 INFO: Looking for eggs
4510 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.6/Python
4512 INFO: Warnings written to /Users/Tomallama/Desktop/Programs/gene_expression/build/gene_expression/warngene_expression.txt
4545 INFO: Graph cross-reference written to /Users/Tomallama/Desktop/Programs/gene_expression/build/gene_expression/xref-gene_expression.html
4555 INFO: checking PYZ
4555 INFO: Building PYZ because out00-PYZ.toc is non existent
4555 INFO: Building PYZ (ZlibArchive) /Users/Tomallama/Desktop/Programs/gene_expression/build/gene_expression/out00-PYZ.pyz
4938 INFO: Building PYZ (ZlibArchive) /Users/Tomallama/Desktop/Programs/gene_expression/build/gene_expression/out00-PYZ.pyz completed successfully.
4944 INFO: checking PKG
4944 INFO: Building PKG because out00-PKG.toc is non existent
4944 INFO: Building PKG (CArchive) out00-PKG.pkg
7984 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
7987 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/bootloader/Darwin-64bit/run
7987 INFO: checking EXE
7987 INFO: Building EXE because out00-EXE.toc is non existent
7987 INFO: Building EXE from out00-EXE.toc
7988 INFO: Appending archive to EXE /Users/Tomallama/Desktop/Programs/gene_expression/dist/gene_expression
8038 INFO: Fixing EXE for code signing /Users/Tomallama/Desktop/Programs/gene_expression/dist/gene_expression
8051 INFO: Building EXE from out00-EXE.toc completed successfully.

然后,当我进入dist文件夹并运行应用程序时,会发生以下情况。

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyInstaller/loader/rthooks/pyi_rth__tkinter.py", line 28, in <module>
    raise FileNotFoundError('Tcl data directory "%s" not found.' % (tcldir))
FileNotFoundError: Tcl data directory "/var/folders/2t/lv424fgn1ml7v_6xs6lkr4hh0000gn/T/_MEIPrF3eT/tcl" not found.
[6771] Failed to execute script pyi_rth__tkinter
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

就像我说的,当我在Windows上运行时,这个过程可以正常工作。但是我无法弄清楚它在Mac上无法工作的原因。我也需要保持使用Python 3.6,因为代码中有f-strings。


你看过Platypus吗?它是一个免费的Mac应用程序,可以将你的Python代码转换为Mac应用程序。我已经使用过它了,效果很好。 - Natsfan
嗯,我还没有尝试过。我会试一下看看能否让它工作。谢谢你的提示。 - Thomas Kellough
https://sveinbjorn.org/platypus - Natsfan
当然。你是否知道如何使用Platypus将其打包成一个文件?当我尝试将应用程序添加到我的Github时,它会自动分成多个下载。 - Thomas Kellough
不,我的情况下应用程序出现在我的桌面上。我没有使用Github。 - Natsfan
显示剩余5条评论
2个回答

2

可以在这里找到说明和解决方法:https://github.com/pyinstaller/pyinstaller/issues/3753

简单来说:在 OS X 上,PyInstaller 存在一个处理 Tcl/Tk 的 bug。修改 hook-_tkinter.py 中的代码可以解决这个问题。

最初的回答来源于上述链接。


1

有一个第三方应用Platypus,可以将可运行的Python代码转换为Mac应用程序。 Platypus易于使用,并且与其他脚本语言(如Perl、Ruby、Swift等)兼容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接