What might be the problems when porting a WxPython program to Linux?

Hello. I am planning to migrate my program from Windows 7 to Linux in the future.
What kind of problems can I encounter and how can I avoid them?

And what can you suggest that should be done immediately when writing the program?

Well, import win32 will fail and also import wx.msw

‘Porting’ should not really be neccesary.
With wx expect some small differences, but it’s easy to keep code portable. Just test on both platforms.
Some features in wx are documented as Windows only.

1 Like

There are a few issues but you find them almost immediately. Making “if” statements works well if you want to run on windows and Linux i.e.:
if sys.platform == ‘win32’:
if sys.platform == ‘win32’:
cmd = ‘start “PES Preview” “%s”’ % (outputfile.strip())
cmd = ‘xdg-open "’ + outputfile.strip() + ‘"’
preview = Popen(cmd, shell=True)
printing on linux

below assumes that we are on Linux and that lp will print a PDF file (ghostscript is part of CUPS)

                # cmd = ("['lp','-d','%s','%s']") %(selectedPrinter.strip(),outputfile.strip())
                # the above does not work on linux
                if "default" in selectedPrinter.lower():
                    cmd = "lp '%s'" % outputfile.strip()
                    cmd = "lp -d %s '%s' " % (selectedPrinter.strip(), outputfile.strip(),)
                sendtoprint = Popen(cmd, shell=True)

As you can see I did not follow all of the wxPython ways to do things - but actually used the platform tools.
hope this helps

1 Like