Pyinstaller 无法导入 scipy.signals [英] Pyinstaller failed to import scipy.signals

查看:102
本文介绍了Pyinstaller 无法导入 scipy.signals的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用导入的模块 scipy.signals 从 python scipt 创建 exe 文件.Pyinstaller 运行良好,没有错误,但新的 .exe 文件给了我这样的错误:

Try to create exe file from python scipt with imported module scipy.signals. Pyinstaller perform well with no errors but new .exe file gives me error like :

Failed to decode wchar_t from UTF-8
MultiByteToWideChar: ╬сырёЄ№ фрээ√ї, яхЁхфрээр  яю ёшёЄхьэюьє т√чютє, ёыш°ъюь ьрыр.
share\jupyter\lab\staging\node_modules\.cache\terser-webpack-plugin\content-v2\sha512\2e\ba\cfce62ec1f408830c0335f2b46219d58ee5b068473e7328690e542d2f92f2058865c600d845a2e404e282645529eb0322aa4429a84e189eb6b58c1b97c1a could not be extracted!

但是当我从 py 文件中更改行时

BUT when I change row in a py file from

from scipy imports signals

import scipy

exec 文件表现出色.有什么建议吗?

exec file perform great. Any suggestions?

推荐答案

我在打包使用 xarray 的脚本时遇到了类似的问题.解决方案是找出哪个包正在导入 jupyter,并将其添加到 excluded-modules 列表中.就我而言,我排除 dask,但在您的情况下,情况会有所不同.

I had a similar issue when packaging up an script that used xarray. The solution was to find out which package was importing jupyter, and add it to the list of excluded-modules. In my case, I excluded dask, but in your case things will be different.

我将使用 --log-level DEBUG 重新运行您的 pyinstaller 命令以获得更多日志信息,然后查看 build/ 中生成的日志文件em> 目录.如果您有 graphviz,或者知道如何使用 graphs,那么您可以分析 .dot 文件以了解安装 em>jupyter/IPython.如果您不知道如何使用 graphviz,没问题,只需在浏览器中打开 html 文件即可.该文件显示了您的脚本导入的所有包,以及这些包导入的所有包,以及由这些包导入的所有包,等等.注意,这是一个非常复杂的包 A 导入网络...包 A 是由 ... 导入的,所以不要迷失在细节中.

I would rerun your pyinstaller command with --log-level DEBUG in order to get some more logging information, then take a look at the log files generated in the build/ directory. If you have graphviz, or know how to work with graphs, then you can analyze the .dot file to learn about the packages that install jupyter/IPython. If you don't know how to use graphviz, no problem, just open up the html file in a browser. This file shows all of the packages imported by your script, and all of the packages that those packages import, and are imported by, etc. Beware, this is a really complex web of package A imports ... and package A is imported by ..., so don't get lost in the details.

此处的目标是找到从您的脚本到导致此问题的 IPython/jupyter 的导入的路径.您想在您的脚本看起来合乎逻辑的任何地方停止此路径.在你的情况下,许多 scipy 子包导入 matplotlib.pyplot,它导入 IPython,它导入最终导入 jupyter_client.您希望通过排除其中一个包来尽早切断从脚本到 jupyter/IPython 的路径.您决定排除的包将取决于您的应用.

The goal here is to find the path of imports that leads from your script to IPython/jupyter that is leading to this issue. You want to stop this path wherever seems logical for your script. In your case, many of the scipy subpackages import matplotlib.pyplot, which imports IPython, which imports things which eventually import jupyter_client. You want to sever this path from your script to jupyter/IPython as early as you can by excluding one of the packages. The package you decide to exclude will depend on your app.

消除此错误的最简单方法是通过 排除 matplotlib 将这个 path 从您的脚本切断​​到 jupyter.但是,如果您在脚本中使用 matplotlib 来生成绘图,则不能这样做.您将不得不选择更下游的包.最终你可以排除 IPython,这应该可以解决问题.查看 pyinstaller 文档以了解如何使用 --exclude-module 参数:

The easiest way to get rid of this error would be to sever this path from your script to jupyter by excluding matplotlib. However, if you use matplotlib in your script to generate plots, then you can't do that. You would have to pick a package that is more downstream. Ultimately you could exclude IPython, and that should do the trick. Take a look at the pyinstaller documentation for how to use the --exclude-module argument:

https://pyinstaller.readthedocs.io/en/stable/usage.html#what-to-bundle-where-to-search

或者这个stackoverflow question有更多信息:

Or this stackoverflow question which has some more info:

如何从 pyInstaller 中删除/排除模块和文件?

附带说明一下,您应该开始习惯排除不必要的包,因为这可以显着减小捆绑应用的大小并提高性能.

On a side note, you should start getting comfortable excluding unnecessary packages since this can drastically decrease the size of your bundled app and improve performance.

这篇关于Pyinstaller 无法导入 scipy.signals的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆