pythoncompilationnuitkapython-standalone

Python standalone compiling with Nuitka


I'm having trouble compiling a simple python script into a standalone executable file. I coded a CLI tool to deploy our front-end app easily but despite trying every combination of parameters I could give to Nuitka, I never manage to get a working standalone script.

At first I was not managing to get the "Requests" module in, as it is the only one I'm using that is not included in Python by default. Now I feel like it IS included by I'm getting errors regarding one of its dependencies.

./cmd.dist/cmd.exe
Traceback (most recent call last):
  File "/home/user/code/cli/cmd.dist/cmd.py", line 12, in <module>
    import requests
  File "/home/user/code/cli/cmd.dist/requests/__init__.py", line 58, in requests
  File "/home/user/code/cli/cmd.dist/requests/utils.py", line 26, in utils
  File "/home/user/code/cli/cmd.dist/requests/compat.py", line 42, in compat
ImportError: No module named packages.ordered_dict

To get an idea, my imports look like that :

from os.path import expanduser
from base64 import b64encode
from io import FileIO
from optparse import OptionParser
from json import dumps
from sys import stdout
from os import path
from os import makedirs
import subprocess
import requests

I'm open to any suggestion on what would be a good way to achieve what I'm trying to do, which is having a simple executable file in /usr/local/bin that's in the path and that can be easily installed on Unix systems, without having to install pip etc


Solution

  • Ok, thanks to @shuttle87, I managed to make everything work by creating a setup.py file with a scripts and entry_points attribute inside it. scripts being an array containing only a path to my sole python file and entry_points being an object looking like so :

      {
        'console_scripts': ['cmd=script:main'],
      },
    

    cmd being the command that you'll be able to call from anywhere to call your script and script:main means that when you type "cmd" it will call the main function from script.py!

    Thank you very much :)