Microsoft Azure管道中的python setup.py build_ext
我在这里读了很多问题/答案,但没有找到我的案例的解决方案 我正在尝试建立我的软件(Python+C)的Windows测试。我正在GitHub项目中使用Azure来测试它。 我需要*.bat文件的命令行解决方案 我调用的批处理脚本Microsoft Azure管道中的python setup.py build_ext,python,windows,azure,msbuild,visual-studio-2019,Python,Windows,Azure,Msbuild,Visual Studio 2019,我在这里读了很多问题/答案,但没有找到我的案例的解决方案 我正在尝试建立我的软件(Python+C)的Windows测试。我正在GitHub项目中使用Azure来测试它。 我需要*.bat文件的命令行解决方案 我调用的批处理脚本 pip install --upgrade setuptools # required by VS python setup.py build_ext --inplace 和接收错误: error: Microsoft Visual C++ 14.0 or great
pip install --upgrade setuptools # required by VS
python setup.py build_ext --inplace
和接收错误:
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
我试图修改我的脚本,如下所示:
pip install --upgrade setuptools
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe" ^
--add Microsoft.VisualStudio.Workload.NativeDesktop ^
--includeOptional ^
--includeRecommended ^
--nocache ^
--quiet
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
python setup.py build_clib
但它看起来在执行过程中挂起,因为VC安装程序需要GUI应答
有人可以给我一个建议,我应该修改我的脚本或提供一些解决方案的链接
简短的“如何在没有用户参与的情况下,通过命令行安装微软C++构建工具”?
谢谢您最好使用VS构建工具,因为您只想使用vc构建工具。VSIDE太大,可能会挂起很长时间。VS构建工具是轻量级的 此外,
--includeOptional将安装其他冗余组件,从而延长安装时间。在这个过程中可能会导致一些意外问题
除外,请使用。它将等待Visual Studio安装程序完成,然后再执行下一个命令
1)下载https://visualstudio.microsoft.com/visual-cpp-build-tools/
2)使用以下命令:
xxx\vs_buildtools.exe --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --nocache --quiet --wait
此外无论如何,安装程序都需要管理员权限才能运行,因此会出现提示框,因此无论您如何操作,都会出现提示,您必须单击它
更新1
谢谢你的反馈,我知道你从虚拟机那里得到了一些权利。而且,似乎您无法通过GUI从Internet轻松获取buildtool.exe
通过脚本获取buildtool.exe
似乎有点复杂,因此使用vs_installer.exe
更方便
使用modify
开关尝试vs_installer.exe
:
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe" modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --nocache --quiet
请注意您应该以管理员身份运行bat文件
,否则会出现管理员权限错误
它将首先执行修改,完成后将运行python文件。您最好使用VS Build Tool,因为您只想使用vc Build Tool。VSIDE太大,可能会挂起很长时间。VS构建工具是轻量级的 此外,
--includeOptional将安装其他冗余组件,从而延长安装时间。在这个过程中可能会导致一些意外问题
除外,请使用。它将等待Visual Studio安装程序完成,然后再执行下一个命令
1)下载https://visualstudio.microsoft.com/visual-cpp-build-tools/
2)使用以下命令:
xxx\vs_buildtools.exe --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --nocache --quiet --wait
此外无论如何,安装程序都需要管理员权限才能运行,因此会出现提示框,因此无论您如何操作,都会出现提示,您必须单击它
更新1
谢谢你的反馈,我知道你从虚拟机那里得到了一些权利。而且,似乎您无法通过GUI从Internet轻松获取buildtool.exe
通过脚本获取buildtool.exe
似乎有点复杂,因此使用vs_installer.exe
更方便
使用modify
开关尝试vs_installer.exe
:
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe" modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional" --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --nocache --quiet
请注意您应该以管理员身份运行bat文件
,否则会出现管理员权限错误
它将首先执行修改,完成后将运行python文件。好的,看起来我放弃了Azure下的“VS构建工具”安装。我没有找到任何可行的方法来做这件事 我所做的: 第1部分。 解决我的原始问题(“Windows下的python setup.py build_ext--inplace”) 仅需要对setup.py进行修改:
if sys.platform in ['win32', 'cygwin']:
os.environ["DISTUTILS_USE_SDK"] = "1"
我查看了setuptools的源代码,发现它试图在Windows中“评估”构建环境。它试图找到许多不同的变量,但失败了。设置这个特定的环境变量可以防止这种内部逻辑,并使用诸如“CC”之类的预设变量来获取编译器名称。我没有深入研究这个逻辑,因为我已经浪费了~周的时间来推动简单的东西在windows上工作。(Python缩短了“hello world”应用程序的编程时间。)
因此,在这种情况下,不需要安装“VS构建工具”(关于Python中有价值的错误消息的问题)
第2部分。
这些是我在Azure环境下安装“VS构建工具”的失败尝试。也许这对将来的人会有帮助
下载:
curl -o webimage.exe ^
--retry 5 --retry-delay 5 ^
-L https://download.visualstudio.microsoft.com/download/pr/9b3476ff-6d0a-4ff8-956d-270147f21cd4/ccfb9355f4f753315455542f966025f96de734292d3908c8c3717e9685b709f0/vs_BuildTools.exe
我不确定链接本身。它今天起作用了,但没有任何保证
打印当前与配置:
echo =============== VS config ===============
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" ^
export ^
--installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" ^
--config "%CD%\vs_config.txt" ^
--passive
type "%CD%\vs_config.txt"
del "%CD%\vs_config.txt"
此配置在安装前后保持不变。也许我打印了一部分,但我已经厌倦了调查这些棘手的事情。组件集是不明确的,因为我没有机会使它工作并减少它
vs_builttool.exe安装
start /b /wait webimage.exe ^
--add Microsoft.VisualStudio.Component.Roslyn.Compiler ^
--add Microsoft.Component.MSBuild ^
--add Microsoft.VisualStudio.Component.CoreBuildTools ^
--add Microsoft.VisualStudio.Workload.MSBuildTools ^
--add Microsoft.VisualStudio.Component.Windows10SDK ^
--add Microsoft.VisualStudio.Component.VC.CoreBuildTools ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^
--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^
--add Microsoft.VisualStudio.Component.Windows10SDK.18362 ^
--add Microsoft.VisualStudio.Component.VC.CMake.Project ^
--add Microsoft.VisualStudio.Component.TestTools.BuildTools ^
--add Microsoft.VisualStudio.Component.VC.ATL ^
--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
--add Microsoft.Net.Component.4.8.SDK ^
--add Microsoft.Net.Component.4.6.1.TargetingPack ^
--add Microsoft.VisualStudio.Component.VC.CLI.Support ^
--add Microsoft.VisualStudio.Component.VC.ASAN ^
--add Microsoft.VisualStudio.Component.VC.Modules.x86.x64 ^
--add Microsoft.VisualStudio.Component.TextTemplating ^
--add Microsoft.VisualStudio.Component.VC.CoreIde ^
--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core ^
--add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset ^
--add Microsoft.VisualStudio.Component.VC.Llvm.Clang ^
--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang ^
--add Microsoft.VisualStudio.Component.Windows10SDK.17763 ^
--add Microsoft.VisualStudio.Component.Windows10SDK.17134 ^
--add Microsoft.VisualStudio.Component.Windows10SDK.16299 ^
--add Microsoft.VisualStudio.Component.VC.v141.x86.x64 ^
--add Microsoft.Component.VC.Runtime.UCRTSDK ^
--add Microsoft.VisualStudio.Component.VC.140 ^
--add Microsoft.VisualStudio.Workload.VCTools ^
--includeOptional --includeRecommended --nocache --wait --passive --quiet ^
--installpath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
del webimage.exe
这里的重要选择是:
--wait
防止shell并行运行进程。你需要确保它在继续之前完成。我不明白谁需要这种默认行为(默认-非阻塞shell命令执行)
在良好的实用程序中类似于“-yes”。此选项不需要用户交互
我希望这篇文章会有帮助,因为我以前没有找到并回答我原来的问题
PS
powershell尝试:
Start-Process -Wait -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList "modify --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --passive --norestart --installpath ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"""
好吧,看起来我放弃了Azure下的“VS构建工具”安装。我没有找到任何可行的方法来做这件事 什么