有没有办法在运行时显式强制编译器构建 Cython 扩展python setup.py install
? Where setup.py
的形式为:
import os.path
import numpy as np
from setuptools import setup, find_packages, Extension
from Cython.Distutils import build_ext
setup(name='test',
packages=find_packages(),
cmdclass={'build_ext': build_ext},
ext_modules = [ Extension("test.func", ["test/func.pyx"]) ],
include_dirs=[np.get_include()]
)
我正在尝试使用 Anaconda 3.16、Python 3.4、setuptools 18、NumPy 1.9 和 Cython 0.24 在 Windows 8.1 x64 上安装包。部署脚本改编自Cythonwiki https://github.com/cython/cython/wiki/CythonExtensionsOnWindows#using-windows-sdk-cc-compiler-works-for-all-python-versions and this https://stackoverflow.com/a/13751649/1791279堆栈溢出答案:
生成文件.bat
:: create and activate a virtual environement with conda
conda create --yes -n test_env cython setuptools=18 pywin32 libpython numpy=1.9 python=3
call activate test_env
:: activate the MS SDK compiler as explained in the Cython wiki
cd C:\Program Files\Microsoft SDKs\Windows\v7.1\
set MSSdk=1
set DISTUTILS_USE_SDK=1
@call .\Bin\SetEnv /x64 /release
cd C:\test
python setup.py install
问题是在这种情况下setup.py install
仍然使用 conda 附带的 MinGW 编译器,而不是 MS Windows SDK 7.1。
-
So the DISTUTILS_USE_SDK=1
and MSSdk=1
似乎对构建没有影响。我不确定从 conda virtualenv 中激活 MS SDK 是否会出现问题。
-
Running python setup.py build_ext --compiler=msvc
使用 MS 编译器正确构建扩展,但随后运行setup.py install
再次用 MinGW 重新编译它。同样适用于python setup.py build --compiler=msvc
.
-
也尝试过跑步%COMSPEC% /E:ON /V:ON /K "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd"
正如上面链接的答案中所讨论的,但对我来说,这会产生一个新的终端提示,颜色为黄色,并停止安装过程。
有没有办法强制编译器构建这个包,例如,通过编辑setup.py
?