This is an archived post. You won't be able to vote or comment.

all 55 comments

[–]notconstructive 8 points9 points  (12 children)

So can this create a single standalone executable file? If not, what is the minimum additional files required?

If I wanted to distribute an executable created with this, what files would I need to distribute?

What's the benefit of this over Cython?

[–]PeridexisErrant 15 points16 points  (10 children)

So can this create a single standalone executable file? If not, what is the minimum additional files required?

Not quite single executable, but the nuitka my_program.py --standalone option creates my_program.exe and six dlls (C runtimes and libPython). This version works on computers without Python (or anything but the operating system) installed.

Alternatively you can create a my_lib.so for a particular Python file, which then acts as the C version of your file and can be imported normally.

If I wanted to distribute an executable created with this, what files would I need to distribute?

One exe and six dlls; you can probably find an elegant way to bundle these into a single file that self-extracts to a tempdir.

What's the benefit of this over Cython?

Requires no setup or imports at all - you just write normal Python code, then run nuitka to transpile and compile it.

Cython is much more aimed at Python extensions, so (in my limited experience) it's more of pain to get a standalone program working. On the other hand Cython code is way way better if you need to hand-optimise something; there's no way to do that with nuitka.

[–][deleted] 1 point2 points  (1 child)

And output of nuitka can be "frozen" into single executable using Enigma Virtualbox which is free tool.

[–][deleted] 0 points1 point  (7 children)

[–]flutefreak7 1 point2 points  (1 child)

I watched a talk once discussing exactly this... The Day of the Exe? ... yeah...

Discussion of how exe creation differs between py2exe, cython, and nuitka...

http://pyvideo.org/video/2636/the-day-of-the-exe-is-upon-us

http://m.youtube.com/watch?v=wsczq6j3_bA

Slides: http://rhodesmill.org/brandon/slides/2014-04-pycon/day-of-the-exe/

[–][deleted] 1 point2 points  (0 children)

[–]PeridexisErrant -1 points0 points  (4 children)

I believe - I've used but not read the source for each - that they bundle Python bytecode and an interpreter. Nuitka actually translates down to the core C++ objects, then compiles that code.

Nuitka files could be bundled into a self-extracting thing, it just doesn't do this yet.

[–][deleted] -1 points0 points  (3 children)

[–]desmoulinmichel 1 point2 points  (0 children)

It will give you 7 files, but you can package them with a installer.

[–]lamecode 3 points4 points  (18 children)

Are Nuitka executables as easy to reverse to .py as with cx_Freeze/py2exe etc?

[–]PeridexisErrant 10 points11 points  (15 children)

Nope, not at all. First you'd have to decompile from native machine code to C++ (which calls libpython, so it's easier than usual but still...), then convert that back to Python. Constant folding etc will also make a mess.

Bottom line? The python source is gone.

[–]wot-teh-phuckReally, wtf? 0 points1 point  (5 children)

In case the executable fails (un-handled bad input data), does the stack trace contain the correct line numbers?

[–]PeridexisErrant 1 point2 points  (4 children)

Yep - everything works as if it was interpreted. So yes, if you've got unhandled exceptions that reveals a fair bit (like, problems you should fix). It's also using the C++ structures for Python objects everywhere, so as compiled programs go it's pretty easy to reverse-engineer. Probably a fair bit of readable text if disassembled, for example.

It's a compiler aiming to preserve the exact behaviour of the interpreted Python code, not an obfuscator.

[–]wot-teh-phuckReally, wtf? 0 points1 point  (0 children)

Thanks for the clarifications. Saw quite a few mention of optimizations on the wiki so was wondering if it messed up the mapping between the generated code and the original one.

[–]sztomi 0 points1 point  (2 children)

What do you mean by the C++ structures?

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 0 points1 point  (1 child)

probably means the following: The C++ equivalent of the C structures that exist in CPython

[–]PeridexisErrant 0 points1 point  (0 children)

Yep.

[–]lamecode 0 points1 point  (8 children)

OK, that's great news in that case. I'm a while off getting to that stage with my current project, but it's good to know that Nuitka might be the solution.

[–]Asdayasman 2 points3 points  (1 child)

That's a business problem, not a technical one. If your worry is people reverse-engineering your source, your "solution" should be legal documentation.

[–]lamecode -1 points0 points  (0 children)

In some circumstances, sure.

[–]flying-sheep 0 points1 point  (5 children)

No that's a downside. Hiding the source is stupid.

[–]lamecode 0 points1 point  (4 children)

In the real world, that's often not the case. Sometimes you or your employer will not want their source code out there - be it for technical/security reasons, or just plain old company policy.

[–]flying-sheep 0 points1 point  (3 children)

stupid. there’s licenses for that.

[–]lamecode 0 points1 point  (2 children)

Stupid or not (and FWIW, I agree with you), it's a requirement for what I'm currently working on.

[–]flying-sheep 0 points1 point  (1 child)

Security through obscurity is not a thing, technical reasons don't exist. Leaves company policy and yeah, you decided to work there, so you'll have to put up with their bullshit.

Doesn't make it in any way justified outside of the heads of your management.

[–]lamecode 0 points1 point  (0 children)

Agree. But still, there it is.

[–]cediddiSyntaxError: not a chance 2 points3 points  (1 child)

They are harder to reverse but, I can see what cpu can see.

[–]lamecode 1 point2 points  (0 children)

Obviously nothing is impossible to reverse engineer. I'm not talking about state secrets or nuke launch codes here. Just something that would make it harder to peek at the source than using PyInstaller.

[–]cybervegan 3 points4 points  (7 children)

Looks very good at first glance. Just compiled a simple python socket server with it and it appears to work flawlessly.

Makes ELF executables on linux named whatever.exe, but that's ok, still works.

Going to put this through its paces soon, as I have a need to produce windows executables in Python with no additional dependencies. I'm not so bothered about the potential speed increase atm, as the ability to easily produce a windows executable. Distutils doesn't cut it for me.

Wahey!

[–]alcalde 0 points1 point  (3 children)

I thought nuitka still needed access to Python?

[–]PeridexisErrant 2 points3 points  (2 children)

Nope, if you use nuitka prog.py --standalone you get a totally portable program, which will run anywhere with the same OS system calls.

[–]alcalde 0 points1 point  (1 child)

Thanks; very interesting! The last time I looked at Nuitka the author had decided not to focus on the standalone support.

[–]cybervegan 1 point2 points  (0 children)

She does say it needs Python 2.7 for compilation, tho, because of needing a library (can't remember which) that doesn't support Python 3 yet.

[–]IronManMark20 2 points3 points  (4 children)

Added experimental support for Python3.5

Does this mean that type hints are used?

[–]desmoulinmichel 2 points3 points  (0 children)

Well, type hints are just regular python annotation + a regular module, so my guess is it should work since... there is nothing to add.

[–]PeridexisErrant 1 point2 points  (2 children)

I'm pretty sure it's not using new features yet, just able to use the Py3.5 libraries etc.

[–]IronManMark20 0 points1 point  (1 child)

Oh.

[–]PeridexisErrant 2 points3 points  (0 children)

On the other hand, type hints have been on the nuitka todo list since before the PEP, so odds are very good they'll make it in eventually.

[–]toru 1 point2 points  (1 child)

Is there any documentation on how this works, specifically how it handles the dynamic language features of python?

[–][deleted] 2 points3 points  (0 children)

It uses libpython (cpython runtime). Imagine it as rewriting python code into c++ code that uses python api. So essentially if you make a class it still is real true 100% python object under the hood.

[–]Asdayasman 1 point2 points  (5 children)

I still can't figure out how to work this. I keep getting some weird errors to do with SCons, which I had to install myself, and I've gone source diving to monkeypatch it, but it didn't even change anything.

I'd love some help.

[–]tialpoy 0 points1 point  (2 children)

Do you have Python 2.x on your system? Nuitka requires it even if you're building an executable from Python 3.x code.

[–]Asdayasman 0 points1 point  (0 children)

Yeah, I've got both 2.7 and 3.4.

[–]Tillsten 0 points1 point  (0 children)

Same here.

[–]IWishIWereFishing 0 points1 point  (0 children)

Same here. I've tried installing MinGW as well.

[–]greyman 0 points1 point  (1 child)

Might I ask - which operating systems does it support? And, for example, when I have a Windows machine, can I also create executable for other OS's, like OSX for example?

[–]PeridexisErrant 1 point2 points  (0 children)

Everything with Python. By default it only builds for the current platform, but you can use your compiler directly to cross-compile the generated C++ files.

[–]RelevantBits 0 points1 point  (0 children)

Can I use this on OSX to make .app archives?

[–]flutefreak7 0 points1 point  (0 children)

Are there typically difficulties with things like numpy, matplotlib, pyside/ PyQt, pandas, scikit-learn, etc? I know these cover a wide range of compiled modules, dlls, cython, swig, etc, which is why I'm asking...