本文介绍了如果脚本包含 import scipy.stats,则 OSX 10.14 脚本使用 pyinstall 编译为独立可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mac OSX 10.14(但不是在 OS 10.12 下)如果脚本包含import scipy.stats"或from scipy import stats",使用 pyinstaller 编译的独立可执行文件将失败

Under Mac OSX 10.14 (but not under OS 10.12) stand-alone executables compiled with pyinstaller fail if the script includes "import scipy.stats" or "from scipy import stats"

蟒蛇 2.7.15.pyinstaller 3.4 scipy 1.2.1macOS 10.14.4

python 2.7.15. pyinstaller 3.4 scipy 1.2.1macOS 10.14.4

脚本使用 python 解释器运行良好,但当使用 pyinstaller -F scriptName.py pyinstaller 编译为单文件可执行文件时,脚本运行成功,但当可执行文件运行时,我收到以下错误.

Scripts run fine using python interpreter, but when compiled as a one-file executable using pyinstaller -F scriptName.py pyinstaller succeeds, but when the executable is run I get the error below.

这在 Windows 或 Linux 下都不会发生,如果我在运行 OS10.12.6 的旧笔记本电脑上编译脚本也不会发生.

This does not happen under either Windows or Linux, and does not happen if I compile the script on an older laptop run OS10.12.6.

我已经更新到最新版本的 pyinstaller 和 scipy.

I have updated to the most recent version of both pyinstaller and scipy.

其余的代码似乎无关紧要.每当导入 scipy.stats 时,可执行文件就会失败.

The rest of the code does not seem to matter. Executable fails whenever scipy.stats is imported.

导入 scipy.stat

s

来自 scipy 导入统计数据

回溯(最近一次调用):文件站点包/PyInstaller/loader/rthooks/pyi_rth_pkgres.py",第 11 行,在文件中"lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py",第 395 行,在 load_module 文件中site-packages/pkg_resources/init.py",第 959 行,在
文件site-packages/pkg_resources/init.py",第 963 行,在环境文件site-packages/pkg_resources/init.py",行190,在get_supported_platform文件中site-packages/pkg_resources/init.py",第 395 行,在get_build_platform 文件sysconfig.py",第 618 行,在 get_platform
文件sysconfig.py",第 482 行,在 get_config_vars 文件中sysconfig.py",第 365 行,在 _init_posix ImportError: No module named_sysconfigdata [18734] 无法执行脚本 pyi_rth_pkgres

Traceback (most recent call last): File "site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 11, in File "lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 395, in load_module File "site-packages/pkg_resources/init.py", line 959, in
File "site-packages/pkg_resources/init.py", line 963, in Environment File "site-packages/pkg_resources/init.py", line 190, in get_supported_platform File "site-packages/pkg_resources/init.py", line 395, in get_build_platform File "sysconfig.py", line 618, in get_platform
File "sysconfig.py", line 482, in get_config_vars File "sysconfig.py", line 365, in _init_posix ImportError: No module named _sysconfigdata [18734] Failed to execute script pyi_rth_pkgres

`

推荐答案

当使用 pyinstaller 构建时使用:

When building with pyinstaller use:

pyinstaller -F scriptName.py --hiddenimport _sysconfigdata

参考:

https://github.com/pyinstaller/pyinstaller/issues/3198

这篇关于如果脚本包含 import scipy.stats,则 OSX 10.14 脚本使用 pyinstall 编译为独立可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 16:47