Installing External Modules into SQL Server’s Python

installpython3

So Microsoft have integrated Python into SQL Server, from the moment I heard that I thought to myself, “wow, this is exciting stuff” and not just for the machine learning, BI guys that it was marketed at.  It’s exciting for us DBAs too, my head was in a buzz with all the things that we could do with it.

That was all well and good but I got even more excited when I realised that we’d not been given some watered down baby python but a full on 12′ long Burmese monster that can also import external modules.

Think about that, all those powerful Python modules that are out there can be imported and used by SQL Server. Crazy stuff!

But how do we go about installing them into SQL Server?  Now I’m a DBA and not a Python wizz so had to do a little digging to figure it out but to be honest, it’s fairly easy.

I don’t know how many other DBAs know that we can install these modules or even how to do it so I thought I’d write up a quick post explaining it.

First things first, you’re going to need to do this from your SQL Server.

Open up a command prompt and navigate to the Python scripts folder, you’ll find that inside the PYTHON_SERVICES directory in your SQL installation location (ie C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES)

(or in the case of my Python test instance…)

installpython

Once there, you can easily install your modules using ‘pip’.  I had no idea what that was either but it turns out that it’s a funky little bit of kit that goes out to the Python Package Index (some mystical cloud location where all the Python goodness lives, known as PyPi by the cool, dev types), downloads and installs modules for you.

how I imagine PyPi looksinstallpython4

 

pip install ModuleName

installpython2

hit enter and your module will download and install, ready for you to have all sorts of fun with.

For a full list and details of the Python modules that are available to you, check out https://pypi.org

That’s just a quickie but hopefully it’ll start you thinking about all the possibilities that Python gives us.

In my next post I’ll give you a fun example of something really cool that I’ve managed to do with Python and an external module.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: