【问题标题】:Problem in compiling C functions in python在python中编译C函数的问题
【发布时间】:2020-01-17 05:08:58
【问题描述】:

信息:

Python 版本:3.7.4

平台:win 10 64 位


我正在尝试使用命令编译文件compileModule.py

python compileModule.py build_ext --inplace 

compileModule.py:

from distutils.core import setup, Extension
from distutils.sysconfig import *
from distutils.util import *
from Cython.Distutils import build_ext
import numpy
import os
import os.path

try:
   from distutils.command.build_py import build_py_2to3 \
       as build_py
except ImportError:
   from distutils.command.build_py import build_py

try:
   from Cython.Distutils import build_ext
except ImportError:
   use_cython = False
else:
   use_cython = True


py_inc = [get_python_inc()]

np_lib = os.path.dirname(numpy.__file__)
np_inc = [os.path.join(np_lib, 'core/include')]
ext_inc = os

sourcefiles = ["utilFunctions.c", "cutilFunctions.pyx"]

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("utilFunctions_C",sourcefiles, libraries=['m'], include_dirs=py_inc + np_inc)]
  )

执行上述命令后出现错误:

 Unable to find vcvarsall.bat

我按照post 上的解决方案下载并安装了 Build Tools for Visual Studio 2017

然后我再次执行以下命令:

python compileModule.py build_ext --inplace 

这给出了一个新的错误:

LINK : fatal error LNK1181: cannot open input file 'm.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x64\\link.exe' failed with exit status 1181

现在我被这个错误困住了。有谁知道如何解决这个错误?

附:我在 Vs 代码中打开了所有 cmd 但仍然是同样的错误:

【问题讨论】:

  • 您是否尝试过从安装 MSBuild 时创建的条目打开命令提示符(在开始菜单的某个位置,但不是普通的命令提示符条目)?如果没有,请先尝试。我相信它设置了可能需要的各种环境变量和路径。
  • 链接器找不到您的标准数学库。这应该在安装工具链的文件夹中,可能在C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.22.27905\\lib(猜测)中。尝试找到您的标准库所在的路径并将其添加到您的include_dirs
  • @blubberdiblub :我看到 4-5 个命令提示符(问题中更新了屏幕截图)。我打开了所有但没有成功
  • @th33lf:请解释您的评论。我在你提到的路径中找到了 3 个文件夹:'onecore'、'x64'、'x86'
  • @AnubhavJhalani 尝试在没有libraries=['m'] 行的情况下构建

标签: python c windows visual-studio compilation


【解决方案1】:

我找到了以下问题的解决方案:

我从compileModule.py 中删除了libraries=['m'],然后文件被编译,没有任何错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多