Docker Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools"

326 Views Asked by At

I am trying to pip install goose3 on a Windows Docker container but I'm getting the following error.

Building wheels for collected packages: pyahocorasick
  Building wheel for pyahocorasick (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pyahocorasick (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'ahocorasick' extension
      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/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyahocorasick
Failed to build pyahocorasick
ERROR: Could not build wheels for pyahocorasick, which is required to install pyproject.toml-based projects

I am using base image FROM mcr.microsoft.com/dotnet/framework/sdk:4.8.1 which according to this documentation should already come with build tools. I also tried this method to add build tools but I'm still getting this error. How do I resolve this error? How can I check which version of Microsoft Visual C++ I have installed in my container? Most of the other answers on this topic require either a browser or the Visual Studio GUI which is not an option for me since I'm using a Docker container. Any help would be appreciated.

For reference, here is my entire Dockerfile:

# Use the latest Windows Server Core 2022 image. With Python 3.12 installed.
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8.1

# Copy build files to the location.
COPY SDWebServer/ Users/Administrator/Downloads/Models/SDWebServer/

# Install chocolatey.
RUN @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

# Install Python.
RUN choco install -y python3
1

There are 1 best solutions below

0
wheeeee On

I was able to get it to work by forcing chocolatey to install Python 3.9 instead of the most recent version of Python. Not sure why this is, since pyahocorasick claims to work with higher versions of Python on their website.