You would need some kind of code obfuscation (and then you could sell the license key to unlock the code). Could use something like https://github.com/dashingsoft/pyarmor perhaps.
But, instead of this unwieldy approach, would you consider monetizing with product support, training, etc.?