I have a Python project (a game) I would like to sell eventually. Would it be considered, by Python standards, acceptable to use a .pyc file instead of a regular .py source file to distribute the game, for security reasons? Would this even be effective? Or, on the other hand, is that just not what .pyc files are for?
-
2Related: https://stackoverflow.com/questions/11368304/what-are-the-limitations-of-distributing-pyc-files – jonrsharpe Dec 25 '17 at 23:11
-
it can be decompiled by someone who really want to do it. Question is how many people will be interested in compiling this. Most users will never think about it, especially if you create .exe file – furas Dec 25 '17 at 23:26
2 Answers
Unless the target platform has the exact same python version installed, this method of distribution simply won't work. See the answer to this question for more information.
Compiled Python bytecode files are architecture-independent, but VM-dependent. A .pyc file will only work on a specific set of Python versions determined by the magic number stored in the file.

- 1,874
- 1
- 8
- 19
Is is 'alright? Yes, the license allows you to distribute .pyc files.
Is is 'effective'? It will most likely be unnecessary, as there will be no commercial reason to copy your work. If it is super good, people will de-compile or write similar games in another language. See jonrsharpe's link.
Is is intended? The main purpose of .pyc files is to avoid unnecessarily re-compiling Python code by caching the result.

- 18,414
- 3
- 40
- 52