or-tools in a windows docker container

Created on 29 Apr 2020  路  4Comments  路  Source: google/or-tools

What version of OR-tools and what language are you using?
Version: master/v7.3/v7.2 etc.
Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
CP-SAT

What operating system (Linux, Windows, ...) and version?
Windows 10

What did you do?
Steps to reproduce the behavior:

I am trying to wrap my api that leverages or-tools in a windows based docker container.
In my container I install the full suite of VS build tools.
However, no matter what I try I can't get this command to pass "python -c "from ortools.linear_solver import pywraplp".
The error that I get is "DLL load failed while importing _pywraplp: The specified module could not be found." which I know is related to "not" having the C++ build tools installed.
Are ideas on other avenues to try? or an active or-tools based docker container for windows?

Anything else we should know about your project / environment

Below is my Dockerfile

FROM mcr.microsoft.com/windows/servercore:ltsc2016

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN (New-Object System.Net.WebClient).DownloadFile('http://download.microsoft.com/download/5/f/7/5f7acaeb-8363-451f-9425-68a90f98b238/visualcppbuildtools_full.exe', 'visualcppbuildtools_full.exe') ; \
    Start-Process .\visualcppbuildtools_full.exe -ArgumentList '/NoRestart /S' -Wait ; \
    rm visualcppbuildtools_full.exe

# Python image
FROM python:3.8.2-windowsservercore

# Set the working directory
WORKDIR /MyProject

COPY . /MyProject

# Install required packages
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
Docker Feature Request Windows

All 4 comments

I was able to figure it out. They key is to use the latest microsoft/dotnet-framework docker container and manually install python into the container instead of calling on the pre-built docker container.

Here is an example DockerFile

# Use latest .NET Framework as base
FROM microsoft/dotnet-framework

# Install Microsoft Visual C++ Redistributable for Visual Studio 2019
ADD https://aka.ms/vs/16/release/VC_redist.x64.exe VC_redist.x64.exe
RUN C:\VC_redist.x64.exe /quiet /install

# Install specific version of python required and add to PATH
ADD https://www.python.org/ftp/python/3.8.2/python-3.8.2-amd64.exe /python-3.8.2-amd64.exe
RUN C:\python-3.8.2-amd64.exe /quiet /install PrependPath=1

# Rest of DockerFile
# Make sure to install ortools through pip here 

Hope this helps anyone searching for this as well.

Maybe the default python is a 32bit one?

I made sure it was the 64bit version. When I was doing the multi-stage build, the python docker container would overwrite the install of the Microsoft Visual C++ Redistributable. That was one of the issues I found when testing the original Dockerfile I posted.

Many Thanks for the feedback !

Was this page helpful?
0 / 5 - 0 ratings