We help IT Professionals succeed at work.

Compile Python Code

e-b
e-b asked
on
33,514 Views
Last Modified: 2011-09-20
I have been searching around for a way to compile my python scripts beyon .pyc or .pyo files mainly because my company would like to distribute some applications however those byte code files are EASILY decompiled by using the disutils module and by any other methods... Also above the fact that a lot of it is still readable in a text editor.

At any rate, I don't want an answer like say it in the EULA or something dumb like that. I'm looking specifically for something to do code obfuscation or compile it to bit code if that is at all possible.

Thanks
Comment
Watch Question

fridomCEO/Programmer
CERTIFIED EXPERT

Commented:
How about py2exe?
http://starship.python.net/crew/theller/py2exe/

Regards
Friedrich
e-b

Author

Commented:
Well I am actually making a bundle for Mac but I believe the scripts for windows are still left in .py/.pyc format someone in the dlls or exe am I correct?

Commented:
As you already mentioned, I'd obfuscate the code, just for the fun of it. :)


fibonacci = lambda x:map(lambda o:(map(lambda c:map(lambda l:
o.__setslice__(l[0],l[1],l[2]),([o[2]+3,o[2]+4,[o[0]]],[0,3,[o[1],
reduce(lambda x,o:x+o,o[:2]),o[2]+1]])),range(x)),o)[1],[[1,1,0]+
range(x)])[0][3:]

print fibonacci(20)
e-b

Author

Commented:
pYrania: Did you have to write that yourself or is there a program to obfuscate your code out there somewhere?

Commented:
you need to write it yourself, else you wouldn't have fun while doing so, right?
e-b

Author

Commented:
writting that above code looks hardly any fun. and if you can write it then why can't someone else read it right?

Commented:
but it's much more pain to fiddle with the obfuscated code than with plain python.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
If you need it compiled and translated into machine code like a traditional computer language, I think you should stay away from Python.

Does your code contain trade secrets or special algorithms developed by your company? We discovered that it did not hurt our interests at all actually giving the source code to the clients. They are really afraid to touch it anyways, and if it got out they would get sued. They appreciate having it, though in case our company somehow disappeared they could hire someone to maintain their system.
EOL

Commented:
Hm, there's recent effords to port python to .Net. As far as I know IronPython is a python-interpreter written in C# that can compile python to .Net bytecode, and makes some .Net libraries accessible. Except math nothing from the python standard library is ported tough. Also you could decide to use jython, and compile your java-app to java-bytecode ( which is as nice to read as python bytecode, but ohwell... )
e-b

Author

Commented:
IronPython is still Alpha
EOL

Commented:
That's true, and I don't think that's at the moment particulary good to use, but hopefully this will change pretty soon.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:

The McMillan Installer will produce a single .exe file in windows. This is probably the easiest solution to the issue of distribution and hiding the code.
There is a program called Jython. You can compile programs to java jar file. You can also code in python and java :).
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.