1

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

  • 2
    Using setuptools and using `python setup.py install` is absolutely the way to do this. – shuttle87 Feb 16 '18 at 08:42
  • pip install -e . would be better no? Because I feel like python setup.py install doesn't install dependencies. Nevertheless, I can't manage to add the script to the path with the scripts attribute in setup.py. Well it allows me to call it with "script.py" but i'd like to call it with just "script". Other than that it seems to work ok with pip install -e so thanks for your suggestion :) Trying to find how to remove the .py at the end of the command now – Martin Vandersteen Feb 16 '18 at 11:03
  • You specify the dependencies in the `setup` as `install_requires` and yes `pip install -e` is what I'd use for developing. Setup.py also has scripts ability which is used for defining the entry points into your program, it can all been done there. – shuttle87 Feb 17 '18 at 01:40

1 Answers1

2

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 :)