Can I run Python in Excel locally?

Wondering if I can run Python in Excel locally… Thanks!

2 Likes

I’m assuming you are asking about where Python runs, not Excel. The only version of Excel with support for Python (initially) is the Windows Desktop version, so that obviously runs locally. But the Python is running on Azure. It’s the full Anaconda distribution, so it has the full pydata stack, but you can’t change/update the packages and you can’t point Excel at a local Python environment.

I can’t speak for why Microsoft chose to run Python on Azure and not allow it to run locally, but I have some personal thoughts on why they went this route.

Security
Python running on Azure cannot access your computer. That alone eliminates a whole lot of security issues that could come from Excel running untrusted code. That was the whole issue with VBA macros and why you have the warning bar in Excel now to enable them. Python in Excel shouldn’t need a warning bar because it can’t harm your computer.

In fact, Python running on Azure is denied access to the internet (except for the connection back to Excel). This limits some of what Python can do, but further eliminates potential security risks of running untrusted code.

Reproducibility
I’m assuming Microsoft doesn’t want Excel users to have to manage a Python environment on their computer. Why not just embed Anaconda inside the Excel executable? That would work initially, but now you can’t update Excel without risk of breaking the spreadsheet (Python libraries aren’t as focused on backwards-compatible changes as Microsoft is). By running Python environments in the cloud, a new environment can be created without removing the existing ones. To update an environment, the spreadsheet could simply point to the new cloud environment, while other spreadsheets continue to point to the old environment. This will allow a 5-year-old spreadsheet to continue giving repeatable results because the Python environment it was developed with is still available in the cloud.

1 Like

Here is someone who can speak for Microsoft:

Hi Rebecca,

The Anaconda Toolbox add-in for Excel just got released in public beta. It has a tool called Anaconda Code which will let you run a Python environment in the add-in. You can find Anaconda Toolbox in the add-in store. Here’s a quick example:

Example of why and how to use Anaconda Code