首页 > 解决方案 > 启动使用 py2app 构建的应用程序时出现“ValueError:源代码字符串不能包含空字节”结果

问题描述

我在运行 Big Sur 的 Mac 上使用 Python 3.9,并尝试从使用 py2app 的脚本创建应用程序 MyApplication_6_14.app。我正在遵循https://py2app.readthedocs.io/en/latest/tutorial.html中概述的过程。

我在使用别名模式开发和运行应用程序时没有任何问题,并且在为部署构建时不会产生错误消息。但是,当我尝试从命令行运行最终应用程序时,我收到以下长度错误消息:

Traceback (most recent call last): File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/__boot__.py", line 115, in <module> _run() File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/__boot__.py", line 84, in _run exec(compile(source, path, "exec"), globals(), globals()) File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/MyApplication_6_14.py", line 7, in <module> import pandas as pd File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/lib/python3.9/pandas/__init__.py", line 179, in <module> import pandas.testing File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/lib/python3.9/pandas/testing.py", line 5, in <module> from pandas._testing import ( File "/Users/fishbacp/Desktop/Python_May_2021/dist/MyApplication_6_14.app/Contents/Resources/lib/python3.9/pandas/_testing.py", line 29, in <module> import pandas._libs.testing as _testing File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing ValueError: source code string cannot contain null bytes

我的设置文件如下所示,由于之前的错误消息,我将 pandas 和 cmath 作为包选项包括在内:

from setuptools import setup

APP = ['MyApplication_6_14.py']
DATA_FILES = []
OPTIONS = {'resources':['background.png'],'packages': ['pandas','cmath']}

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

标签: pythonpy2app

解决方案


推荐阅读