Nuitka standalone isn't really standalone

10.4k views Asked by At

I plan on using a Python (3.6) script for a project, though the final user is likely not to have Python on his system. To solve this issue and make everything as smooth as possible, I tried using Nuitka to compile my Python script and make it standalone.

To do that, I just ran

nuitka --standalone --recurse-all myscript.py

Doing this takes a certain amount of time, but finally results in a folder with a myscript.exe that I can run just like I would run my script.

Though, as soon as I try and run it on another computer, no matter whether it has Python installed, I get an error thrown:

Traceback (most recent call last):
  File "D:\Users\thoma\Desktop\recuperation.dist\recuperation.py", line 6, in <module>
  File "D:\Users\thoma\Desktop\recuperation.dist\requests\__init__.py", line 43, in requests
  File "D:\Users\thoma\Desktop\recuperation.dist\urllib3\__init__.py", line 8, in urllib3
  File "D:\Users\thoma\Desktop\recuperation.dist\urllib3\connectionpool.py", line 7, in connectionpool
  File "C:\Users\Thomas\AppData\Local\Programs\Python\Python36\lib\socket.py", line 49, in <module>
ModuleNotFoundError: No module named '_socket'

Also, I had trouble getting it to work in the beginning, because it was missing cacert.pem, but I solved that by copying the certifi folder that I found coming with requests. Don't know if it relates.

My script is using Requests, Dill, BS4 (and also json, base64, os and sys)

2

There are 2 answers

0
101 On

Since Python 3.3 __init__.py files are not required in Python modules. Nuitka can sometimes ignore modules in the build based on the presence of these files. A workaround would be to manually add them if they're not there.

0
Rotareti On

The --standalone option does not (yet) produce a single file binary. In order to run myscript.exe on another machine, you have to provide all the files you find in the output directory of nuitka.

Luckily there is work in progress to allow compilation to single file binaries: https://github.com/Nuitka/Nuitka/issues/230