2

I made a (one file) scrip in python for my client, the program is a success and now it needs to be distributed to 12 of my client employees.

The script I made uses a lot of libraries (imports), some of then are not popular at all so here goes the question:

Is there a way to distribute my program already compiled in bytecode? So the users can run it by just simply doing "python myProgram.pyc" or just "myProgram.pyc" (if it has +x property), I know this is entirely possible in Java by compiling the libraries inside a JAR file, is there anything similar for python?

Please don't recommend me py2exe since is far away for what I want, either other similar tools, I just want to distribute a package with all the necessary libraries already pre-compiled in bytecode so the final users don't need to worry about installing libs, pip, github, custom stuff, or anything. Hope you can help me, if not I will have to port the whole project to Java.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Possible duplicate of [Is there a way to embed dependencies within a python script?](http://stackoverflow.com/questions/11436777/is-there-a-way-to-embed-dependencies-within-a-python-script) – William Price Mar 16 '16 at 03:50
  • No is not, since the accepted answer in that thread is from 2012 and it proposes a deprecated method, I suppose now @ 2016 there must be a simpler, faster, safest, tool to do what I want – Diego Diaz Valdez Mar 16 '16 at 04:29

1 Answers1

2

If your client employees machine are Windows go for py2exe http://py2exe.org/

If Mac go for py2app https://pypi.python.org/pypi/py2app/

cx_Freeze http://cx-freeze.sourceforge.net/ is cross-platform and it should spit out executable that would run on any OS with Python installed.

PyInstaller http://www.pyinstaller.org/ is a good one too.

However, these methods do not compile and hence improve run-time performance improvements. Rather a way to distribute your script as a single executable with all the necessary modules.

You could use the compiled .pyc file with a wrapper around it for execution and package it as a single executable. However, performance improvements of doing so is debatable.

EDIT: It's been long though, recently started with cython and it could be a plausible solution for this problem. If not all, defining the variable types should do that is asked in the question.

Bussller
  • 1,961
  • 6
  • 36
  • 50
  • Please read my question, I want to avoid at all cost py2exe or py2app, what I want is to distribute a JAR/ZIP like package with all the necessary libraries embedded in it, so the users can just run my program without installing anything else. I had been looking for days and nothing worked so far, now I am porting my app to Java, damn python. – Diego Diaz Valdez Mar 16 '16 at 08:51
  • Hi @Diego, pyinstalker dies the same. It packages everything into a self contained compressed package. On double clicking or running be ./ in Linux would not require any external dependancy. The py2exe and py2app does the same. May be you can try before porting to java. I did use py2app, pyinstaller and CX_freeze for couple of my python applications and worked. I was able to distribute where the user can run simply by running. Doesn't require any installation. – Bussller Mar 16 '16 at 19:32
  • It is you who has to install py2exe to generate the single self contained executable not your client, if you've misunderstiod – Bussller Mar 16 '16 at 19:33
  • Again the conversion to binary is not a good solution at all, it makes the script super heavy with lot of useless dependencies, employees will have to install VB C runtime in their windows machines, to say more... pyinstaller doesn't even work with my script probably because custom libraries and py2exe requires python 3.3, my conclusion is Python while is good for quick developing it SUCKS for distributing specially to "no tech" people, I will never use it again. – Diego Diaz Valdez Mar 17 '16 at 04:04
  • Even, I had custom libraries. But was able to package them with the distributable with proper configuration file. I do not understand what do you mean by super heavy by lot of useless dependencies. While your decision to switch to some other language is personal, it is possible to package them as a single executable without unnecessary dependencies, as far my experience goes. Or I may not completely understand what you're looking for? If possible please elaborate on your question or comment. – Bussller Mar 17 '16 at 04:21