Will Python code written in Windows be compatible with Linux?

Question:

I would like to write some Python code on Windows using PyQt. However, before doing so, I would like to confirm whether the code I write in Python will be compatible. Although the compiled program may not work due to different platforms, would there be any issues with the *.py files that I write on Windows compared to Linux?

I have been attempting to install PyQt on my Mint system, but I am unsure of the problem. This is why I would like to explore this option.

Moreover, I would like my code to be functional on Raspberry PI.

Asked By: Nepze Tyson

||

Answers:

Mostly, yes, as long as you keep to using the tools Python provides you and don’t write code that is platform specific.

Use os.path.join() to build paths, for example. Open files in binary mode when you deal with binary data, text mode when it’s text data. Etc.

Python code itself is platform agnostic; the interpreter on Linux can read python code written on Windows just fine and vice versa.

The general rule of thumb is to pay attention to the documentation of the modules you are using; any platform specific gotchas should be documented.

Answered By: Martijn Pieters

It depends on what your code does. Most packages work in both windows and linux however some such as signal only work in windows and are not portable. But in the python docs it will say what platforms a given package works in.

Answered By: JonathanV
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.