简体   繁体   English

冷冻 Python 中的 Scipy:无法导入名称 nonlin

[英]Scipy in frozen Python: Cannot import name nonlin

I am creating a Windows EXE using cx_freeze, Python3 and the Scipy installation from lfd.uci.edu.我正在使用 cx_freeze、Python3 和来自 lfd.uci.edu 的 Scipy 安装创建一个 Windows EXE。 Upon running the exe, I receive the error: ImportError: cannot import name nonlin .运行 exe 后,我收到错误: ImportError: cannot import name nonlin

The Scipy file line this references, in site-packages\scipy\optimize_root.py: from . import nonlin这里引用的 Scipy 文件行,在 site-packages\scipy\optimize_root.py: from . import nonlin from . import nonlin . from . import nonlin

I can load a console with Python, and successfully run import scipy.optimize.nonlin .我可以使用 Python 加载控制台,并成功运行import scipy.optimize.nonlin Adding scipy.optimize.nonlin to my setup.py includes doesn't solve the problem.将 scipy.optimize.nonlin 添加到我的 setup.py 包含并不能解决问题。

nonlin.py is located in the optimize directory in my scipy install, and its corresponding location as a compiled file in the library file cx_freeze generates. nonlin.py 位于我的 scipy 安装中的优化目录中,其对应位置为库文件 cx_freeze 生成的编译文件。

I had the same trouble, but nonlin was imported in "/scipy/optimize/ init .py" file.我遇到了同样的麻烦,但是 nonlin 被导入到“/scipy/optimize/ init .py”文件中。 It is marked as "# Deprecated namespaces, to be removed in v2.0.0".它被标记为“# Deprecated namespaces, to be removed in v2.0.0”。 You can just comment the string in file, where import nonlin is.您可以只注释文件中的字符串,其中 import nonlin 是。 It worked for me.它对我有用。

The reason I'm backing to this thread is that recently a friend of mine asked for help around this issue.我支持这个线程的原因是最近我的一个朋友就这个问题寻求帮助。

Given that, here is the same solution approach: Circular dependency while executing cx_Freeze result鉴于此,这里是相同的解决方法: Circular dependency while execution cx_Freeze result

In the setup script, just add the package failure references as below:在设置脚本中,只需添加包失败引用,如下所示:

packages = ["scipy.optimize", "scipy.integrate", ...] 

I've had a lot of issues with cx_Freeze and Scipy.我在使用 cx_Freeze 和 Scipy 时遇到了很多问题。 The only thing I really found to work was to either add the missing module to the "includes" option or to manually add the needed files to the "include_files" option.我真正发现的唯一工作是将缺少的模块添加到“includes”选项中,或者手动将所需的文件添加到“include_files”选项中。

This link helped me with interpolation.这个链接帮助我进行插值。 https://bitbucket.org/anthony_tuininga/cx_freeze/issue/43/import-errors-when-using-cx_freeze-with https://bitbucket.org/anthony_tuininga/cx_freeze/issue/43/import-errors-when-using-cx_freeze-with

{"includes": ["scipy.special._ufuncs_cxx"],
 "include_files": [(python_exe_path+"/Lib/site-packages/scipy/sparse/sparsetools/_csr.pyd",
                    "_csr.pyd") ],
}

This isn't exactly the same problem for you, but it may help you find the needed files to include them properly.这对您来说不是完全相同的问题,但它可以帮助您找到所需的文件以正确包含它们。 "includes" didn't work for you, so you could manually add it with "include_files" or "zip_includes" depending on where it is searching for your file. “includes”对您不起作用,因此您可以根据搜索文件的位置使用“include_files”或“zip_includes”手动添加它。

{"zip-include": (python_exe_path+"/Lib/site-packages/scipy/optimize/nonlin.py, 
                 "scipy/optimize/nonlin.py")}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM