简体   繁体   English

构建 Python 扩展失败(“kernel32.lib”无法打开 |“x64”与目标机器类型“x86”冲突)

[英]Building Python extension fails ("kernel32.lib" cannot be opened | "x64" conflicts with target machine type "x86")

I am trying to install the python extension line-profiler via pip on a fresh installation of Anaconda3.我正在尝试在全新安装的 Anaconda3 上通过 pip 安装 python 扩展line-profiler As the package requires a compiler, I have installed the Visual Studio Build Tools 2019 along with the Windows 10 SDK.由于该包需要编译器,我已经安装了 Visual Studio Build Tools 2019 和 Windows 10 SDK。 In particular, I have installed特别是,我已经安装

  • MSVC v142 – VS 2019 C++-x64/x86-Buildtools (v14.27) MSVC v142 – VS 2019 C++-x64/x86-Buildtools (v14.27)
  • Windows 10 SDK (10.0.18362.0) Windows 10 SDK (10.0.18362.0)
  • MSVC v141 – VS 2017 C++-x64/x86-Buildtools (v14....) MSVC v141 – VS 2017 C++-x64/x86-Buildtools (v14....)
  • MSVC v140 – VS 2015 C++-Buildtools (v14.00) MSVC v140 – VS 2015 C++-Buildtools (v14.00)

I am working on 64bit Windows 10, build 18363.1082.我正在使用 64 位 Windows 10,构建 18363.1082。

To make sure that all compiler files needed are found, I have added the following entries to the PATH environment variable:为了确保找到所有需要的编译器文件,我在 PATH 环境变量中添加了以下条目:

  • C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64 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)\\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 C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.27.29110\\bin\\Hostx64\\x64

Now when I run现在当我跑

pip install line-profiler

I get the error message我收到错误消息

fatal error LNK1104: file "kernel32.lib" cannot be opened

even though the file kernel32.lib is clearly present in one of the folders added to PATH above.即使文件kernel32.lib明显存在于添加到上面 PATH 的文件夹之一中。 (Full error log at the end of this question) (此问题末尾的完整错误日志)

After some research, I have found that operating in the Developer Command Prompt for VS 2019 can help resolve this issue, as it loads some batch files on startup.经过一番研究,我发现在 VS 2019 的开发人员命令提示符中操作可以帮助解决此问题,因为它会在启动时加载一些批处理文件。 I have thus opend this command prompt, activated my Anaconda environment and run the same command again.因此,我打开了这个命令提示符,激活了我的 Anaconda 环境并再次运行相同的命令。 Now I get the error现在我得到了错误

fatal error LNK1112: machine type "x64" is in confilict with the target machine type "x86".

How can I set up VS to compile extensions properly?如何设置 VS 以正确编译扩展? In particular, I wonder我特别想知道

  1. How can I set up the anaconda prompt (or any other prompt) so that the correct kernel32.lib is always found?如何设置 anaconda 提示(或任何其他提示)以便始终找到正确的kernel32.lib
  2. How can I facilitate that the x64 version of the extension is created (clearly I am working on x64)我如何促进创建扩展的 x64 版本(显然我正在使用 x64)

The full error messages are below (freely translated from German where necessary)完整的错误消息如下(必要时从德语免费翻译)

ERROR: Command errored out with exit status 1:
   command: 'C:\Users\user\Anaconda3\python.exe' 'C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\user\AppData\Local\Temp\tmpvbz5hf82'
       cwd: C:\Users\user\AppData\Local\Temp\pip-install-vluz_z60\line-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 CMakeFiles\cmTC_9b999.dir\testCCompiler.c.obj
      [2/2] Linking C executable cmTC_9b999.exe
      FAILED: cmTC_9b999.exe
      cmd.exe /C "cd . && C:\Users\user\AppData\Local\Temp\pip-build-env-bxchh6aq\overlay\Lib\site-packages\cmake\data\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_9b999.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~3\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_9b999.dir\testCCompiler.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~2\MICROS~3\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_9b999.dir\testCCompiler.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:CMakeFiles\cmTC_9b999.dir/intermediate.manifest CMakeFiles\cmTC_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:\Users\user\AppData\Local\Temp\pip-build-env-mf957mv5\overlay\Lib\site-packages\cmake\data\bin\cmake.exe -E vs_link_dll --intdir=line_profiler\CMakeFiles\_line_profiler.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x86\mt.exe --manifests  -- C:\PROGRA~2\MICROS~3\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\Hostx86\x86\link.exe /nologo line_profiler\CMakeFiles\_line_profiler.dir\_line_profiler.c.obj line_profiler\CMakeFiles\_line_profiler.dir\unset_trace.c.obj line_profiler\CMakeFiles\_line_profiler.dir\timers.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:\Users\user\Anaconda3\libs\python38.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~2\MICROS~3\2019\BUILDT~1\VC\Tools\MSVC\1427~1.291\bin\Hostx86\x86\link.exe /nologo line_profiler\CMakeFiles\_line_profiler.dir\_line_profiler.c.obj line_profiler\CMakeFiles\_line_profiler.dir\unset_trace.c.obj line_profiler\CMakeFiles\_line_profiler.dir\timers.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:\Users\user\Anaconda3\libs\python38.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.

The issue is that not all environment variables are set properly.问题是并非所有环境变量都设置正确。 To do this, the file C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat can / needs to be executed.为此,可以/需要执行文件C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat This is (almost) done on the startup of Develper Command Prompt, which explains why the kernel32.lib is found if working within this console.这(几乎)是在 Develper 命令提示符启动时完成的,这解释了为什么在此控制台中工作时会找到 kernel32.lib。

The second error occurs, because the Develper Command Prompt does not execute the x64 version of the script and thus sets variables to the paths of the x86 compilers.出现第二个错误,因为开发人员命令提示符不执行 x64 版本的脚本,因此将变量设置为 x86 编译器的路径。 Using the "x64 Native Tools Command Prompt for VS 2019" (can be found in the start menu) solves the issue.使用“x64 Native Tools Command Prompt for VS 2019”(可以在开始菜单中找到)解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:致命错误 LNK1112:模块机器类型“x64”与目标机器类型“x86”冲突 - Python: fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86' 带有SEEK_END的fseek返回“无效参数”错误,以在Windows7 x64上使用python x86 C扩展库管理大数据(7GB) - fseek with SEEK_END returns a “Invalid argument” error to manage large data(7GB) with python x86 C extension lib on windows7 x64 如何为x86计算机重新编译x64 blender python脚本? - How to recompile an x64 blender python script for x86 computers? x64 Python Wheels是否需要x86 Visual C ++库? - Are the x86 Visual C++ libraries needed for x64 Python Wheels? Windows x64上可返回的Python 2. * x86(ie32bit)id()函数的最高数目是多少? - What is the highest number Python 2.* x86 (i.e.32bit) id() function on Windows x64 can return? DLL加载失败,同时没有为x86和x64 DLL显示有效的Win32应用 - DLL Load Failed, Not a Valid Win32 App showing for both x86 & x64 DLLs 尝试使用python 2.7.8在x32上运行x64机器的代码 - trying to run code for x64 machine on x32 with python 2.7.8 使用Armadillo和MKL库为x86(win32)构建 - Building with Armadillo and MKL libraries for x86 (win32) 我如何知道要返回哪个实际的dll(x86 v x64)? - How do I tell which actual dll is being returned (x86 v x64)? Windows x64 vs x86:硬件 vs. 操作系统 vs. 进程 - Windows x64 vs x86: Hardware vs. OS vs. process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM