Python:使用py2app在MacOS上制作独立的可执行文件
我在python脚本my_app.py
中有一个应用程序,想在MacOS(10.14)上制作一个独立的可执行文件.在视频教程此处之后,我依次输入了以下命令:
I have an application in a python script my_app.py
and want to make a standalone executable out of it on a MacOS (10.14). Following the video-tutorial here, I entered sequentially the following commmands:
pip install virtualenv
virtualenv venv --system-site-packages
source venv/bin/activate
pip install py2app
cd /path/to/my_app.py
python setup.py py2app -A
以及以下setup.py
文件:
from setuptools import setup
APP = ["my_app.py"]
DATA_FILES = []
OPTIONS = {
"argv_emulation": True,
"packages": ["certifi"],
}
setup(
app = APP,
data_files = DATA_FILES,
options = {"py2app": OPTIONS},
setup_requires = ["py2app"]
)
但收到以下错误消息:
Traceback (most recent call last):
File "setup.py", line 13, in <module>
setup_requires = ["py2app"]
File "/Users/mymac/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
return distutils.core.setup(**attrs)
File "/Users/mymac/anaconda3/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/mymac/anaconda3/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Users/mymac/anaconda3/lib/python3.7/distutils/dist.py", line 984, in run_command
cmd_obj.ensure_finalized()
File "/Users/mymac/anaconda3/lib/python3.7/distutils/cmd.py", line 107, in ensure_finalized
self.finalize_options()
File "/Users/mymac/venv/lib/python3.7/site-packages/py2app/build_app.py", line 567, in finalize_options
if isinstance(self.plist, plistlib.Dict):
AttributeError: module 'plistlib' has no attribute 'Dict'
收到该错误消息后,我发现 github页面并键入以下代码:
With that error message, I found that github page and typed the following code:
brew install qt # will install qt-5.x.x
brew install libxml2
make qt5py3
python3 labelImg.py
python3 labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
As a side note, if mssing pyrcc5 or lxml, try
pip3 install pyqt5 lxml
但是,在输入make qt5py3
行之后,我得到了:
However after entering the line make qt5py3
, I get:
make: *** No rule to make target `qt5py3'. Stop.
我还尝试了以下命令:
brew install python3
pip install pipenv
pipenv --three
pipenv shell
pip install py2app
pip install PyQt5 lxml
make qt5py3
rm -rf build dist
python setup.py py2app -A
mv "dist/labelImg.app" /Applications
但也得到
make: *** No rule to make target `qt5py3'. Stop.
输入行make qt5py3
我在github上发布了问题
I posted an issue on github
我在做什么错了?
plistlib.Dict
可用,但未记录.在python 3.4中,它最终被记录;还记录了它从3.0开始不推荐使用.
plistlib.Dict
was available but not documented. In python 3.4 it was finally documented; also documented that it's deprecated since 3.0.
在python 3.7中,它不再记录,并且可能已从plistlib
库中删除.
In python 3.7 it is no longer documented and perhaps removed from plistlib
library.
这意味着py2app
当前尚未与Python 3.7兼容.我发现了这个问题,据报道半年前,几天后解决.解决方法是:使用以下命令将py2app
升级到最新版本0.15:
This means that py2app
currently not yet compatible with Python 3.7. I found this issue, it was reported half a year ago and resolved a few days later. The resolution is: upgrade py2app
to the latest version 0.15 with the following command :
pip3.7 install -U py2app
验证版本
pip show py2app