osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to achieve pyc only deployment for module in python3.6


Chandana Pattanayak <chandana.pattanayak at patterneffectslabs.com> writes:

> I have a requirement to provide basic code protection for a module in our
> product suite. With python 3.6 the .pyc files are created under pycache ,
> so if i remove the py file the module is not found anymore.

One approach could be to define and register your own
import hook, similar to the "zipimporter".
Such import hooks allow to find modules in non standard places,
such as in a zip archive.
Of course, you would need to implement the import hook in
a standard place (accessible with the standard Python import mechanism).

Another approach could be, that you move the created "*.pyc" files
to standard import places for deployment.


Note that you can disassemble "*.pyc" files and gain
quite some insight by this. Thus, the protection provided
by not deploying the source files is basic indeed.