问题
I'm trying to use pyodbc to import a dataframe in Azure ML Workbench. This works in local runs, but not for docker. It fails when trying to establish a connection to the SQL Server, because the driver is not present.
cnxn = pyodbc.connect('DRIVER='{ODBC Driver 13 for SQL Server}';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password)
Error Message:
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)")
When searching for a solution i found that i could put these lines in the docker file
ADD odbcinst.ini /etc/odbcinst.ini
RUN apt-get update
RUN apt-get install -y tdsodbc unixodbc-dev
RUN apt install unixodbc-bin -y
RUN apt-get clean -y
However I'm new to docker, and cannot figure out where to put these lines in the ML Workbench. It seems the docker file is generated through docker.compute and conda_dependencies.yml, but nothing similar to the lines above can be found in either of those or anywere else in the solution.
回答1:
You can build docker image with dependencies you need and specify your image name inside the docker.compute file:
baseDockerImage:<your docker image name>
I created azml_pyodbc image, you can try to use it with:
baseDockerImage: "aksanakuzmitskaya/azml_pyodbc:firsttry"
DRIVER='{ODBC Driver 17 for SQL Server}'
来源:https://stackoverflow.com/questions/48885715/how-do-you-use-pyodbc-in-azure-machine-learning-workbench