首页 > 解决方案 > 使用 py2app 预期的 str、字节或 os.PathLike 对象创建可执行文件时出错,而不是 NoneType

问题描述

我正在尝试使用 py2app 创建可执行文件,但出现此错误,我不确定如何修复它,也不确定是否正确包含所有文件。

我的工作目录如下所示:

directory
  -- app_icon.png
  -- app_loading.gif
  -- app_logo.png
  -- detector.pb
  -- model.py
  -- myapp.py
  -- VGG16_weights.h5
  -- VGG16.h5

我的 setup.py 看起来像这样:

from setuptools import setup

APP = ['myapp.py']
DATA_FILES = ['app_icon.png', 'app_loading.gif', 'app_logo.png', 'VGG16.h5', 'VGG16_weights.h5', 'detector.pb']
OPTIONS = {
    'argv_emulation': True
}

setup(
    app=APP,
    py_modules=['model'],
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=["py2app"],
)

当我执行 python myapp.py 时,我的应用程序运行正常,但是在我使用创建可执行文件之后

python setup.py py2app -A

当我跑步时

./dist/myapp.app/Contents/MacOS/myapp

应用程序崩溃,我收到以下错误:

Traceback (most recent call last):
  File "/Users/luis/Desktop/py2appexec/dist/myapp.app/Contents/Resources/__boot__.py", line 450, in <module>
    _run()
  File "/Users/luis/Desktop/py2appexec/dist/myapp.app/Contents/Resources/__boot__.py", line 444, in _run
    exec(compile(source, script, "exec"), globals(), globals())
  File "/Users/luis/Desktop/py2appexec/myapp.py", line 3, in <module>
    import model as custom_model
  File "/Users/luis/Desktop/py2appexec/model.py", line 2, in <module>
    import tensorflow as tf
  File "/Users/luis/virtualenvironment/executable/lib/python3.7/site-packages/tensorflow/__init__.py", line 732, in <module>
    plugin_dir = _os.path.join(s, 'tensorflow-plugins')
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
2020-01-20 11:06:20.690 myapp[3806:164925] myapp Error

在寻找路径时似乎它变得空,但我不知道为什么或如何修复它,有什么解决方案吗?

标签: pythonmacosexecutablepy2app

解决方案


我有一个类似的问题。py您的文件中有哪些软件包?也许您可以尝试将包添加到您的setup.py文件中。例如,我的OPTIONS变量中有这个:

OPTIONS = {
    'argv_emulation': True,
    'packages':['pygame']}

我也会尝试查看/Users/luis/Desktop/py2appexec/dist/myapp.app/Contents/Resources/并查看提到的文件,看看是否缺少某些东西。我缺少图像,尽管我认为您的问题可能会有所不同。一旦我将图像添加到文件夹中,它就可以正常工作。


推荐阅读