0

I am working on a project which has below directory structure

MyPythonProject
    -> configs
        -> appconfig.json
    -> logs
        -> app.log
    -> src
        -> file1.py
        -> file2.py
        -> file3.py 
    app.py

app.py is the main executable file which is also depended on python files inside src. I want to convert app.py to app.exe which I can easily do using pyinstaller app.py. This creates a dist folder which has python and all the packages. I can simply copy paste the src, configs and logs into dist and can easily share it with everyone.

But the problem is I do not want to share python files inside src as it is because it can easily accessed by anyone. I want to convert it into binary executable so that no one can convert or de-compile back into .py files.

For this, I can use auto generated .pyc files but I believe this can also be de-compiled back to py. Is there any way I can convert into some kind of binary which can never be de-compiled. Does pyinstaller do this. Is there any command available in pyinstaller which while converting app.py also converts rest of the python files into executable. Please help. Thanks

S Andrew
  • 5,592
  • 27
  • 115
  • 237
  • You could include the files into one executable using `--onefile` however I believe `pyinstaller` [can still be decompiled](https://reverseengineering.stackexchange.com/questions/160/how-do-you-reverse-engineer-an-exe-compiled-with-pyinstaller)? – PacketLoss Sep 18 '20 at 03:48
  • @PacketLoss Pyinstaller creates exe so I am sure it will be difficult to decompile. I will look at your link. But anyways can you explain a bit more on `--onefile`. Does using `--onefile` it also creates exe for other files – S Andrew Sep 18 '20 at 04:05
  • There is a good answer already on how to use multiple files in `--onefile` [here](https://stackoverflow.com/a/59710336/7942856) follow the answer to add more files, then include `--onefile` to compile into one executable. – PacketLoss Sep 18 '20 at 04:16
  • @PacketLoss I am getting error in commands. Looks like I am not issuing correct commands. I am checking pyinstaller documentation as well but if you can answer, that would be great. – S Andrew Sep 18 '20 at 05:46
  • Are you importing the files in `src`? – PacketLoss Sep 18 '20 at 06:00
  • @PacketLoss I am using this command `pyinstaller --onefile --add-data 'src/.*py:src' app.py` – S Andrew Sep 18 '20 at 06:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221672/discussion-between-packetloss-and-s-andrew). – PacketLoss Sep 18 '20 at 06:06

1 Answers1

1

If you are importing the additional scripts, pyinstaller will gather those imports and automatically include them.

You can use --onefile to ensure only the exe is created for distribution.

pyinstaller --onefile app.py

PacketLoss
  • 5,561
  • 1
  • 9
  • 27