我正在使用cx_Freeze将python脚本转换为exe文件。
不幸的是,创建该exe文件后,我得到了AttributeError
:
AttributeError:类型对象'scipy.interpolate.interpnd.array'没有 属性“ reduce_cython ”
使用的版本: 的Python:3.7.3 Scipy:1.2.1 Cython:0.29.7 cx_Freeze:5.1.1
我已经将所有使用的模块升级到最新版本,并搜索错误。我还尝试再次卸载并重新安装模块。
我使用了以下cx_Freeze setup.py
:
from cx_Freeze import setup, Executable
import os
# Set environment variables
# https://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-i-use-cx-freeze
os.environ['TCL_LIBRARY'] = r'C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\tcl\tk8.6'
includes = ["numpy", "numpy.core._methods", "numpy.lib.format", "sklearn", "ipaddress", "schwifty", "pandas", "multiprocessing.pool", "pkg_resources._vendor", "appdirs", "sklearn.ensemble.forest", "packaging.version", "packaging.specifiers", "packaging.requirements", "xgboost", "email.mime.text", "email.mime.multipart", "idna.idnadata", 'scipy._distributor_init', 'scipy.sparse.csgraph._validation', "cython", "scipy.interpolate.interpnd", "scipy"]
setup(name = "fraudDetection",
version = "0.1",
description = "",
options = {'build_exe': {'includes': includes}},
executables = [Executable("fraudDetection.py")]
)
我希望exe文件能够运行并给出预测(欺诈检测),但我收到此错误消息(每次启动exe文件时):
编辑:更新了错误文件
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "fraudDetection.py", line 40, in <module>
from sklearn import preprocessing
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\sklearn\preprocessing\__init__.py", line 6, in <module>
from ._function_transformer import FunctionTransformer
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 5, in <module>
from ..utils.testing import assert_allclose_dense_sparse
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\sklearn\utils\testing.py", line 21, in <module>
import scipy.io
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\scipy\io\__init__.py",
line 97, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\scipy\io\matlab\__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\scipy\io\matlab\mio.py",
line 10, in <module>
from .miobase import get_matfile_version, docfiller
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\scipy\io\matlab\miobase.py", line 22, in <module>
from scipy.misc import doccer
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\scipy\misc\__init__.py",
line 68, in <module>
from scipy.interpolate._pade import pade as _pade
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\scipy\interpolate\__init__.py", line 175, in <module>
from .interpolate import *
File "C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Anaconda3_64\lib\site-packages\scipy\interpolate\interpolate.py", line 32, in <module>
from .interpnd import _ndim_coords_from_arrays
File "stringsource", line 105, in init scipy.interpolate.interpnd
AttributeError: type object 'scipy.interpolate.interpnd.array' has no attribute '__reduce_cython__'
谢谢您的任何建议!
答案 0 :(得分:0)
正如@ead和@DavidW所评论的那样,您发布的错误消息表明,鉴于路径中的Python36
文件夹,Scipy是从Python 3.6安装中导入的。
File "C:\Users\user.name\AppData\Roaming\Python\Python36\site-packages\scipy\interpolate\interpolate.py"
但是也许您只是忘了编辑错误消息的这一部分。
无论如何,您可以添加以下行
import sys
import scipy
print(sys.version)
print(scipy.__version__)
访问setup.py
文件,以查看cx_Freeze构建可执行文件时实际使用的是哪个版本的Python和Scipy。
在Cython github存储库中对相同的错误消息进行了广泛的讨论,请参见Issue #1953。您可能在那里找到更多建议。
根据此讨论,该错误是由Cython中的一个问题引起的,该问题已在Cython 0.28中得以解决。您还可以在其中找到以下有用的comment:
[...]如果您安装的某个软件包是使用具有错误的旧Cython版本构建的,则仅在系统上安装Cython版本x.y完全无关紧要。
由于原因固定为0.28,我现在将关闭这张票。如果您发现使用0.28或更高版本构建的软件中发生了类似的问题,请打开一张新票。
编辑:要验证Cython实现的软件包是否使用正确的Cython版本构建,请解压缩其源代码分发包(来自PyPI的
*.tar.gz
),找到.c
或.cpp
文件并查看其第一行。如果显示的是/* Generated by Cython 0.28 */
或更高版本,则包含此修复程序。如果版本较旧,则不包含此修复程序,在这种情况下,最好向项目要求新版本。
因此,您还需要检查所有使用Cython生成并包含在可执行文件中的软件包是否已使用Cython 0.28或更高版本进行了构建。