Search code examples
pythonlinuxexcelvagrantpywin32

Porting Python on Windows using pywin32/excel to Linux on Vagrant Machine


I have written an extensive python package that utilizes excel and pywin32. I am now in the progress of moving this package to a linux environment on a Vagrant machine.

I know there are "emulator-esque" software packages (e.g. WINE) that can run Windows applications and look-a-likes for some Windows applications (e.g. Excel to OpenOffice). However, I am not seeing the right path to take in order to get my pywin32/Excel dependent code written for Windows running in a Linux environment on a Vagrant machine. Ideally, I would not have to alter my code at all and just do the appropriate installs on my Vagrant machine.

Thanks


Solution

  • The short answer is, you can't. WINE does not expose a bottled Windows environment's COM registry out to linux—and, even if it did, pywin32 doesn't build on anything but Windows.

    So, here are some options, roughly ordered from the least amount of change to your code and setup to the most:

    • Run both your Python script and Excel under real Windows, inside a real emulator.
    • Run both your Python script and Excel under WINE.
    • Write or find a library that does expose a bottled Windows environment's COM registry out to Linux.
    • Write or find a cross-platform DCOM library that presents a win32com-like API, then change your code to use that to connect to the bottled Excel remotely.
    • Rewrite your code to script Excel indirectly by, e.g., sshing into a Windows box and running minimal WSH scripts.
    • Rewrite your code to script LibreOffice or whatever you prefer instead of Excel.
    • Rewrite your code to process Excel files (or CSV or some other interchange format) directly instead of scripting Excel.