使用pyximport在python中导入cython文件会导致导入错误:因为distutils.error.compileError
我从中学习了github代码。我要调试此文件: 我补充说使用pyximport在python中导入cython文件会导致导入错误:因为distutils.error.compileError,python,mingw,cython,importerror,distutils,Python,Mingw,Cython,Importerror,Distutils,我从中学习了github代码。我要调试此文件: 我补充说 from sklearn.datasets.samples_generator import make_blobs bandwidth=0.5 num_mean_shift_iterations=5 num_points=100 centers = [[-1, -1], [-1, 1], [1, -1], [1, 1]] x1, y = make_blobs(n_samples=num_points, centers=centers, c
from sklearn.datasets.samples_generator import make_blobs
bandwidth=0.5
num_mean_shift_iterations=5
num_points=100
centers = [[-1, -1], [-1, 1], [1, -1], [1, 1]]
x1, y = make_blobs(n_samples=num_points, centers=centers, cluster_std=0.4, random_state=42)
clustering = MeanShift(bandwidth=bandwidth, n_jobs = -1, max_iter=num_mean_shift_iterations).fit(x1)
在_mean_shift.py中。我使用安装了Python 3.7的Sypder环境运行它
下面是完整的错误
ImportError: Building module utils.murmurhash failed ["distutils.errors.CompileError:command 'C:\\\\Program Files (x86)\\\\Microsoft Visual Studio\\\\2019\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.24.28314\\\\bin\\\\HostX86\\\\x64\\\\cl.exe' failed with exit status 2\n"]
其中utils.hash是我试图在位于不同位置的python文件中导入的内容
我已经用python创建了一个新环境:即,此网页上列出的所有库都已安装
包含以下代码的distutils.cfg位于:
C:\Users\username\Anaconda3\envs\stan\u env\Lib\distutils\distutils.cfg
[build]
compiler=mingw32
[build_ext]
compiler = mingw32
我使用了:
import pyximport
pyximport.install()
在导入cython_文件之前在python文件中
请给我指出错误。谢谢。我看到您正在使用:
import pyximport
pyximport.install()
编译Cython以导入*.pyx文件
上面写着:
如果您的模块不需要任何额外的C库或特殊的生成设置,那么您可以使用pyximport模块
可能会导致问题,因为sklearn导入了许多C库
要导入*.pyx,首先必须通过运行以下命令对其进行编译:
# change directory to forked project ([example-how-to-do-that][2])
# only for Windows users with anaconda:
conda activate {environment_name} # the same name which you provided during environment creation
# only for linux users who don't use anaconda:
# source {environment_name}/bin/activate
python setup.py build_ext --inplace
在候机楼
当我试图直接在代码中编译Cython模块(通过pyximport包)时,我也遇到了问题。我不能进口。在我的情况下,它也是来自sklearn的文件。通过终端编译Cython的方法对我很有帮助。这个问题缺乏答案,如果没有答案,就不可能判断出问题所在。@ead我已经将这些步骤添加到了可重复性最小的示例中。请调查一下这个问题。谢谢。1)必须有关于打印到stderr的错误的更多信息2)仍然不清楚您要对哪些文件进行加密/编译。3) 为什么要重新编译这个文件?我只是在运行这个文件:使用上面提到的更改。此文件中使用的函数是在哈希中实现的。BurruHash是cython文件,它正在通过函数调用进行cythonized。如果将该文件导入到我尝试使用的python文件中,如何避免重新编译?