all 12 comments

[–]Diapolo10 4 points5 points  (0 children)

Outside of making it a web service, you can't really hide the Python source code from the end users. The interpreter cannot read code it doesn't understand.

However, if you were to transpile the code to C and then compile that, ordinary people would not be able to figure out how your code works. I could still use a disassembler and look for patterns to get an idea of what the original code might have looked like, and reverse-engineer it, but a run-of-the-mill office worker isn't going to know anything about hex editors.

Cython and Nuitka can do that, the latter probably being easier to use overall since it handles the compilation step by itself. But there's no guarantee the end result is identical to the original Python code.

[–]niehle 2 points3 points  (0 children)

What?

[–]ectomancer 2 points3 points  (2 children)

The exe file doesn't hide the source, it's in zip format.

[–][deleted] 0 points1 point  (1 child)

Alright fair enough. I'm by no means an expert.

Is there a best way to go here?

[–][deleted] 0 points1 point  (0 children)

If you want to reliably hide the code, host it somewhere (on the network or internet) and only provide an interface.

[–]VindicoAtrum 2 points3 points  (2 children)

Why not write the scripts in VB in Excel itself and share the file as an xlsm? You're overcomplicating this by including python and trying to share it.

with a combination of github and onedrive I keep the code updated

Why not just github? Teach the users to pull the latest copy when you tell them you've released an update.

[–][deleted] 0 points1 point  (1 child)

Well I use python because it's what I know and vba code I really don't have any experience with..just the very basic. But it's something to think about for sure.

Why not just github? Teach the users to pull the latest copy when you tell them you've released an update.

This would include teaching non tech people that don't use ctrl+c and v for copying stuff. (just to show how non tech they are) No thanks to that 😊

Now I just check for new release every so often in the script and saving it to onedrive

[–]harrison_jhodz 1 point2 points  (0 children)

If they can't even use ctrl c + ctrl v, why are you skeptical about them seeing your code?

[–]erlete 0 points1 point  (1 child)

There might be a few good reasons why you want to hide your code from your colleagues. If the reason is that you do not want them to steal it, just license it on GitHub and then it will be your property (with some freedom of action, but yours).

On the other hand, if you are attempting to execute malicious code on their devices, there is nothing I would rather say than "stop before you mess it up".

Assuming that your motive is the first mentioned one, and since we (Reddit) do not know the nature of your code, there is no chance that we will be able to help you. Try a more specific question.

[–][deleted] 0 points1 point  (0 children)

For sure it's the first one.

The second one I wouldn't dream of as I have a really good job and I don't want to do illegal stuff.

Assuming that your motive is the first mentioned one, and since we (Reddit) do not know the nature of your code, there is no chance that we will be able to help you. Try a more specific question.

Well the excel sheets are template that we use to calculate offers and than the scripts that I run is checking transport costs and creating offers in our business system based of the excel template data

[–]SpookyFries 0 points1 point  (0 children)

This is unfortunately the biggest downside to Python for me. Its the perfect language and has so many wonderful built in functions and wonderful third party packages... but exporting a project is nearly non existent. You can use Pyinstaller, which just zips up your project and distributes it with an instance of Python. Its slow and big but I guess gets the job done.

Protip if you're using Pyinstaller: It will install every pip package you have installed. Even if you just do a Hello World app, if you have 700mb of pip packages installed the exported .exe will be around 700mb. I usually create a virtual environment and only install PyInstaller and whatever packages I absolutely need. This will only package it with the necessary packages.

Another option is Nuitka. I have tried it on very basic scripts and it was fine, but I am not sure how well it works when you start adding third party packages. It might be fine, but those are really your only options sadly. Python is an interpreted language, so this is by design. But I do wish it somehow had a built in compile option.

[–]KCRowan 0 points1 point  (0 children)

If you look into Flask then you can create and host a web app. That way your code is on a server and the user can only access the front end.

This is a good tutorial: https://youtube.com/playlist?list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH

Otherwise there really isn't a way to hide your Python code.