我正试图通过pip在新安装的Anaconda3上安装python扩展line-profiler
。由于该软件包需要编译器,我已经安装了Visual Studio Build Tools 2019以及Windows 10 SDK。特别是,我安装了
- MSVC v142–VS 2019 C++-x64/x86 Buildtools(v14.27(
- Windows 10 SDK(10.0.18362.0(
- MSVC v141–VS 2017 C++-x64/x86 Buildtools(v14….(
- MSVC v140–VS 2015 C++-Buildtools(v14.00(
我正在64位Windows 10上工作,版本18363.1082。
为了确保找到所有需要的编译器文件,我在PATH环境变量中添加了以下条目:
- C:\Program Files(x86(\Windows Kits\10\Lib\10.0.18362.0\um\x64
- C: \Program Files(x86(\Windows Kits\10\bin\10.0.18362.0\x64
- C: \Program Files(x86(\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64
现在当我运行时
pip install line-profiler
我收到错误信息
fatal error LNK1104: file "kernel32.lib" cannot be opened
即使文件CCD_ 2清楚地存在于上面添加到PATH的文件夹之一中。(本问题末尾的完整错误日志(
经过一些研究,我发现在VS 2019的开发者命令提示符中操作可以帮助解决这个问题,因为它在启动时加载一些批处理文件。因此,我打开了这个命令提示符,激活了我的Anaconda环境,并再次运行相同的命令。现在我得到错误
fatal error LNK1112: machine type "x64" is in confilict with the target machine type "x86".
如何设置VS以正确编译扩展?特别是,我想知道
- 如何设置anaconda提示(或任何其他提示(,以便始终找到正确的
kernel32.lib
- 我如何帮助创建x64版本的扩展(很明显,我正在使用x64(
完整的错误消息如下(必要时可从德语自由翻译(
ERROR: Command errored out with exit status 1:
command: 'C:UsersuserAnaconda3python.exe' 'C:UsersuserAnaconda3libsite-packagespip_vendorpep517_in_process.py' build_wheel 'C:UsersuserAppDataLocalTemptmpvbz5hf82'
cwd: C:UsersuserAppDataLocalTemppip-install-vluz_z60line-profiler
Complete output (217 lines):
Not searching for unused variables given on the command line.
-- The C compiler identification is MSVC 19.27.29112.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Users/user/AppData/Local/Temp/pip-build-env-bxchh6aq/overlay/Lib/site-packages/cmake/data/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/user/AppData/Local/Temp/pip-install-vluz_z60/line-profiler/_cmake_test_compile/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Users/user/AppData/Local/Temp/pip-build-env-bxchh6aq/overlay/Scripts/ninja.exe cmTC_9b999 && [1/2] Building C object CMakeFilescmTC_9b999.dirtestCCompiler.c.obj
[2/2] Linking C executable cmTC_9b999.exe
FAILED: cmTC_9b999.exe
cmd.exe /C "cd . && C:UsersuserAppDataLocalTemppip-build-env-bxchh6aqoverlayLibsite-packagescmakedatabincmake.exe -E vs_link_exe --intdir=CMakeFilescmTC_9b999.dir --rc=C:PROGRA~2WI3CF2~110bin100183~1.0x64rc.exe --mt=C:PROGRA~2WI3CF2~110bin100183~1.0x64mt.exe --manifests -- C:PROGRA~2MICROS~32019BUILDT~1VCToolsMSVC1427~1.291binHostx64x64link.exe /nologo CMakeFilescmTC_9b999.dirtestCCompiler.c.obj /out:cmTC_9b999.exe /implib:cmTC_9b999.lib /pdb:cmTC_9b999.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:PROGRA~2MICROS~32019BUILDT~1VCToolsMSVC1427~1.291binHostx64x64link.exe /nologo CMakeFilescmTC_9b999.dirtestCCompiler.c.obj /out:cmTC_9b999.exe /implib:cmTC_9b999.lib /pdb:cmTC_9b999.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFilescmTC_9b999.dir/intermediate.manifest CMakeFilescmTC_9b999.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: Datei "kernel32.lib" kann nicht geöffnet werden.
ninja: build stopped: subcommand failed.
FAILED: line_profiler/_line_profiler.cp38-win_amd64.pyd
cmd.exe /C "cd . && C:UsersuserAppDataLocalTemppip-build-env-mf957mv5overlayLibsite-packagescmakedatabincmake.exe -E vs_link_dll --intdir=line_profilerCMakeFiles_line_profiler.dir --rc=C:PROGRA~2WI3CF2~110bin100183~1.0x86rc.exe --mt=C:PROGRA~2WI3CF2~110bin100183~1.0x86mt.exe --manifests -- C:PROGRA~2MICROS~32019BUILDT~1VCToolsMSVC1427~1.291binHostx86x86link.exe /nologo line_profilerCMakeFiles_line_profiler.dir_line_profiler.c.obj line_profilerCMakeFiles_line_profiler.dirunset_trace.c.obj line_profilerCMakeFiles_line_profiler.dirtimers.c.obj /out:line_profiler_line_profiler.cp38-win_amd64.pyd /implib:line_profiler_line_profiler.lib /pdb:line_profiler_line_profiler.pdb /dll /version:0.0 /machine:X86 /INCREMENTAL:NO /EXPORT:PyInit__line_profiler C:UsersuserAnaconda3libspython38.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:PROGRA~2MICROS~32019BUILDT~1VCToolsMSVC1427~1.291binHostx86x86link.exe /nologo line_profilerCMakeFiles_line_profiler.dir_line_profiler.c.obj line_profilerCMakeFiles_line_profiler.dirunset_trace.c.obj line_profilerCMakeFiles_line_profiler.dirtimers.c.obj /out:line_profiler_line_profiler.cp38-win_amd64.pyd /implib:line_profiler_line_profiler.lib /pdb:line_profiler_line_profiler.pdb /dll /version:0.0 /machine:X86 /INCREMENTAL:NO /EXPORT:PyInit__line_profiler C:UsersuserAnaconda3libspython38.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:line_profiler_line_profiler.cp38-win_amd64.pyd.manifest" failed (exit code 1112) with the following output:
python38.lib(python38.dll) : fatal error LNK1112: Modul-Computertyp "x64" steht in Konflikt mit dem Zielcomputertyp "x86".
ninja: build stopped: subcommand failed.
问题是并非所有环境变量都设置正确。为此,可以/需要执行文件C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCAuxiliaryBuildvcvars64.bat
。这(几乎(是在Develper命令提示符启动时完成的,这解释了为什么在这个控制台中工作时会发现kernel32.lib。
出现第二个错误,因为Develper命令提示符不执行x64版本的脚本,因此将变量设置为x86编译器的路径。使用";x64 Native Tools命令提示符for VS 2019";(可以在开始菜单中找到(解决了这个问题。