[Python] How can I use Nuitka to import all script's modules?

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I try to turn a .py file into a .bin file with Nuitka.

    Since it have to work on machine without python installed, I use the --standalone option that comes with --follow-imports and --python-flag=no_site options to import my modules. I use --onefile too, if I understand well, this option makes folders useless (only the .bin is necessary).

    So I use the command: python3 -m nuitka --standalone --follow-imports --python-flag=no_site --onefile myscript.py.

    The command works and I have my .bin (plus 3 folders (.build, .dist, .onefile-dist)).

    I try to execute my program:

    ./myscript.bin

    with the head:

    #!/usr/bin/python3
    from pathlib import Path
    from cryptography.fernet import Fernet
    import subprocess
    import math
    from math import gcd


    and I got a "No module named" error, but only on the second import I do. I conclude Nuitka import correctly the first package, so the .bin works as well as the .py on this point, but don't import this second package like the .py does.

    Looking for similar problems on the Internet, I only found differences between the versions of Nuitka and the package versions as follows.

    But when I use python3 --version and nuitka --version, I got this:

    Python 3.12.3


    and

    2.7.2
    Commercial: None
    Python: 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]
    Flavor: Debian Python
    Executable: ~/venv/bin/python3
    OS: Linux
    Arch: x86_64
    Distribution: Linuxmint (based on Ubuntu) 22
    Version C compiler: /urs/bin/gcc (gcc 13).


    We can see the same Python version for both so it's not the problem. In this case, what is the problem? Are there some modules that we just can NOT import in the .bin?

    I specify that I'm on a Linux Mint 22 VM and in a virtual environment (create with python -m venv venv) because it was necessary to use pip to install (and in result use) Nuitka. Try to execute the .bin in or out the venv give the same result.

    Continue reading...

Compartilhe esta Página