在脚本导入时,Spyder无法识别cython模块

时间:2018-04-14 23:37:45

标签: python import module cython spyder

我有一个带有各种功能的cython脚本example1.pyx。我试图在我的python脚本中使用这些函数之一。为此,我只是尝试从cython模块导入函数,如下所示:

    from example1 import myfunction1

我正在使用Spyder来运行我的python脚本。当我运行它时,我收到以下错误

    ModuleNotFoundError: No module named 'example1'

由于某种原因,.pyx扩展脚本无法识别为可导入的模块。我可以成功导入其他python脚本,但没有运气cython .pyx脚本。结果我没有编译python脚本。所以我使用以下脚本这样做了:

from setuptools import setup, Extension
import numpy

from Cython.Distutils import build_ext as _build_ext


list_pyx = ['cydtw', 'cygak', 'cycc', 'soft_dtw_fast']
ext = [Extension(
        '%s' % s, ['%s.pyx' % s], include_dirs=[numpy.get_include()]
    ) for s in list_pyx]

setup(
    include_dirs=[numpy.get_include()],
    ext_modules=ext,
    cmdclass={'build_ext': _build_ext},
)

当我运行它时,我得到错误说我需要Visual C ++ 14.0编译器。查看https://wiki.python.org/moin/WindowsCompilers中的文档,我已安装的Visual Studio 15应该具有Visual C ++ 14.0,因此令人困惑。所以我更新了我的setuptools。摆脱了这个错误,但事实证明我找不到文件路径C; \ program files \ Microsoft SDKs \ Windows \ v8.1 \ lib。我可以看到它没有。这就是我现在被困住的地方。有线索吗?

1 个答案:

答案 0 :(得分:0)

管理以解决此问题。没有在Visual Studio 2015上安装Visual C ++编译器。

要检查,请打开Visual Studio 15。

查看Visual C ++下的模板。

我可以看到需要安装的Windows桌面的Visual C ++ 2015工具。

这包括Windows桌面的工具和库,其中包括编译器,Universal CRT和Windows 8.1 SDK。跑了安装。在此期间它会要求你关闭视觉工作室。

能够编译cython脚本以及在我的python项目中调用脚本中的函数。

我会说你必须要小心你的编译器版本和python版本匹配。可能存在兼容性问题。

有关Visual Studio构建工具的详细信息,请访问: https://landinghub.visualstudio.com/visual-cpp-build-tools

对于安装非纯python包或编译cython或pyrex文件,兼容性方面的详细信息如下: https://wiki.python.org/moin/WindowsCompilers

相关问题