Skip to main content
Dave Mason - Mastodon Dave Mason - LinkedIn Dave Mason - GitHub Dave Mason - Counter Social

Visual Studio: Create a Python Environment from SQL Server 2017 Machine Learning Services

Dave Mason SQL Server 2017 Visual Studio Python

I'm starting to experiment with Python scripts in SQL Server 2017 using Machine Learning Services (In-Database). The problem is, I don't know Python. If I run into a Python error, the output I get from SSMS is not looking too helpful. My instincts tell me I'll be much better off developing and debugging Python code from a development tool. What I settled on was to use Visual Studio along with the Python interpreter that comes with SQL Server 2017 Machine Learning Services. I ran into a few issues that I'll review here.

The first thing I did was Install Python support in Visual Studio on Windows. This article from Microsoft was simple enough. It worked for me with Visual Studio Community 2015. I quickly created a "PythonApplication1" project and tried Hello World. But I got an error telling me Visual Studio couldn't find any interpreters.

Dave Mason SQL Server 2017 Visual Studio Python Dave Mason SQL Server 2017 Visual Studio Python


To add an interpreter to Visual Studio, select View | Other Windows | Python Environments. That opens the Python Environments window. Click on "+ Custom ...". Enter whatever you want in the Description field (I chose "SqlServerPythonServices"). In the Prefix Path field, enter the PYTHON_SERVICES path from the SQL Server 2017 installation. This is the default: "C:\Program Files\Microsoft SQL Server\MSSQL14.SQL2017\PYTHON_SERVICES". Then click Auto Detect. Visual Studio auto-magically fills in the remaining fields. Lastly, click Apply.

Dave Mason SQL Server 2017 Visual Studio Python Dave Mason SQL Server 2017 Visual Studio Python Dave Mason SQL Server 2017 Visual Studio Python


Now when I re-run my project, the error message is gone and I see my "Hello world!" output.

Dave Mason SQL Server 2017 Visual Studio Python


It looks like multiple Python environments can be set up for different Python interpreters. But I don't have that need myself. As I mentioned, I don't know Python, so I haven't done anything beyond Hello world. I'll add some follow-up notes here if I encounter any related issues. Happy coding!

Comments

Post comment