Python:使用py2app在MacOS上制作独立的可执行文件

时间:2019-02-23 22:58:36

标签: python python-3.x virtualenv executable py2app

我在python脚本my_app.py中有一个应用程序,想在MacOS(10.14)上制作一个独立的可执行文件。在视频教程here之后,我依次输入了以下命令:

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 page并键入了以下代码:

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行之后,我得到了:

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上发布了issue

我在做什么错了?

1 个答案:

答案 0 :(得分:2)

plistlib.Dict可用,但未记录。在python 3.4中,它最终是documented;还记录了它从3.0开始不推荐使用。

在python 3.7中,它不再documented,并且可能已从plistlib库中删除。

这意味着py2app当前尚未与Python 3.7兼容。我发现了这个issue,它是半年前报告的,几天后解决了。解决方法是:使用以下命令将py2app升级到最新版本0.15:

pip3.7 install -U py2app

验证版本

pip show py2app