It looks like you're new here. If you want to get involved, click one of these buttons!
Is there any way to encrypt/compile the referred files, like the way of .py to .pyc of python works, so their contents are not accessible and readable from the user, but still can be used from KLayout?
That's not a good analogy, as .pyc isn't there for encryption, but just to save the time for parsing the source code. Python will remove comments in this step, but I think even variable names are still visible inside .pyc. It's also possible to decompile .pyc back into .py.
Encryption of data files doesn't work for open source - anyone can hack into the code and dump the data after encryption.