0

I have a Python program that uses the command line like below

parser = argparse.ArgumentParser()
parser.add_argument("-I", "--example", help="Example: -I example")

When I go to run this I do

py .\name_of_file.py -I example

This is working fine, but the problem I have now is that 'name_of_file.py' calls functions in other files, imports other files, etc. This requires the user to have access to the source code, so this is obviously not a good solution. How can I still add the command line capability while putting the source code behind a wall or an executable or something along those lines?

Luke
  • 138
  • 2
  • 11
  • 2
    You cannot obfuscate python – roganjosh Feb 03 '23 at 20:22
  • 1
    With Python, you can't. That's the trade-off. Python interprets your code at run-time, so your code has to be available. Even if you "compile to exe", that's just wrapping your code into a zipfile that the interpreter can run later.' – Tim Roberts Feb 03 '23 at 20:22
  • You would have to distribute at least the`pyc` files containing the necessary byte code. An executable would just be a bundle containing a Python runtime and all the source code needed to run your application. In general, you can't distribute Python programs without distributing the source as well. – chepner Feb 03 '23 at 20:22
  • I mean, you can, but it affords you no protection from anything – roganjosh Feb 03 '23 at 20:23
  • 2
    Did you read any of these already: https://stackoverflow.com/questions/261638/how-do-i-protect-python-code-from-being-read-by-users, https://stackoverflow.com/questions/1558385/how-can-i-distribute-python-programs, https://stackoverflow.com/questions/12059509/create-a-single-executable-from-a-python-project, https://stackoverflow.com/questions/527510/how-to-deploy-a-python-application-with-libraries-as-source-with-no-further-depe, https://stackoverflow.com/questions/15913367/how-can-i-distribute-a-python-program-without-requiring-users-to-have-a-python-r – mkrieger1 Feb 03 '23 at 20:23
  • Is your concern that the users can *see* the source code or that they *need* the source code? – mkrieger1 Feb 03 '23 at 20:25
  • Do you know [auto-py-to-exe](https://pypi.org/project/auto-py-to-exe/)? – Hermann12 Feb 03 '23 at 20:35

0 Answers0