最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does Nuitka onefile mode displays my python code in tracebacks? - Stack Overflow

programmeradmin1浏览0评论

Here is an example code:

while True:  # here is a comment
    pass

Here is my Python and Nuitka version:

D:\test>py -m nuitka --version
2.6.8
Commercial: None
Python: 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)]
Flavor: CPython Official
Executable: ~\AppData\Local\Programs\Python\Python38-32\python.exe
OS: Windows
Arch: x86
WindowsRelease: 10
Version C compiler: ~\AppData\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\mingw32\bin\gcc.exe (gcc 14.2.0).

I ran the command py -m nuitka --standalone --onefile test.py and finally got test.exe. Then I ran test.exe and pressed Ctrl+C in the windows terminal. I got a traceback like this:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Temp\ONEFIL~3\test.py", line 1, in <module>
    while True:  # here is a comment
KeyboardInterrupt
^C

I found the source code even with the comment. But most people say that programs compiled by Nuitka is irreversible. So what's wrong?

Here is an example code:

while True:  # here is a comment
    pass

Here is my Python and Nuitka version:

D:\test>py -m nuitka --version
2.6.8
Commercial: None
Python: 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)]
Flavor: CPython Official
Executable: ~\AppData\Local\Programs\Python\Python38-32\python.exe
OS: Windows
Arch: x86
WindowsRelease: 10
Version C compiler: ~\AppData\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\mingw32\bin\gcc.exe (gcc 14.2.0).

I ran the command py -m nuitka --standalone --onefile test.py and finally got test.exe. Then I ran test.exe and pressed Ctrl+C in the windows terminal. I got a traceback like this:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Temp\ONEFIL~3\test.py", line 1, in <module>
    while True:  # here is a comment
KeyboardInterrupt
^C

I found the source code even with the comment. But most people say that programs compiled by Nuitka is irreversible. So what's wrong?

Share Improve this question asked Mar 11 at 14:37 Zxd2025Zxd2025 1717 bronze badges 6
  • I think to encrypt all traceback outputs you have to buy the Commercial version. – Lewis Commented Mar 11 at 14:55
  • @Lewis I only found this problem in onefile mode. Programs built with py -m nuitka --standalone test.py only show line numbers, but not the code. I think encryption won't solve this because the message is still there and maybe can be found using reverse engineering. – Zxd2025 Commented Mar 11 at 15:13
  • 2 In the Nuitka page you can read that the standard edition bundles the code, dependencies and data into a single executable. The Nuitka Commercial additionally protects the code, data and outputs. – Lewis Commented Mar 11 at 15:28
  • 1 @JonSG I create an answer with the links to the Nuitka page. – Lewis Commented Mar 11 at 17:50
  • @Lewis Thank you. But I still cannot explain why isn't the code displayed when I turned off the onefile mode. Does the same thing happens on your computer? – Zxd2025 Commented Mar 12 at 13:45
 |  Show 1 more comment

2 Answers 2

Reset to default 2

In the Nuitka page you can read that

Nuitka Standard
The standard edition bundles your code, dependencies and data into a single executable if you want. It also does acceleration, just running faster in the same environment, and can produce extension modules as well. It is freely distributed under the Apache license.

Nuitka Commercial
The commercial edition additionally protects your code, data and outputs, so that users of the executable cannot access these. This a private repository of plugins that you pay to get access to. Additionally, you can purchase priority support.

So to encrypt all traceback outputs you have to buy the Commercial version.

In this Nuitka Commercial you can see the features only Nuitka Commercial offers.


Onefile:

  • Creates a single executable file. When this executable runs, it extracts its contents to a temporary directory. If the source code is within the folder where the onefile is placed, then Nuitka can find it and display the source code in tracebacks.

Standalone:

  • Creates a directory containing the executable and all its dependencies. By default this would create a dist folder, but the source code is not included in the folder. Because of that Nuitka can't display the source code in tracebacks.

For Nuitka to display source code lines within tracebacks, the original Python source files must be present in the same location when the compiled program is executed.

I found the problem. It's my mistake.

In this issue /Nuitka/Nuitka/issues/2175, it is mentioned that if the source code is there, it will be accessible. With --onefile, the program is placed in the same directory D:\test\, otherwise the program is placed in D:\test\test.dist\. There is no source code in D:\test\test.dist\ so Nuitka can't find it so there is no code displayed in tracebacks.

So I think this won't happen if the program is distributed without the source code.

发布评论

评论列表(0)

  1. 暂无评论