Compile python module imports
Question: I have a problem. I write a python script to make my work faster and now I
want to share it with my team.

I don't want them to mess with some imports that are missing in the basic
python installation. I know there is a way to compile python to exe, but I
wonder if I can compile the code and the imports without messing with py2exe.

Does python have a built-in solution for that?

I saw that python have pyc compile option. Does it compile the import modules
as well?

Thanks, Or


Answer: No I don't believe you have a built-in standalone compilation mode native to
Python. The pyc is a compiled code but not the kind you usually distribute as
an executable program (meaning you would still need the Python interpreter).

If you don't want to use py2exe or other similar packages I advise you to use
a portable version of Python with which you can distribute your software (see
for example [WinPython](http://winpython.github.io/)). The easiest way to
accomplish this is by giving the portable distribution together with your code
and perhaps a batch file (or similar, if you want to have a .exe alike
behavior).

NOTE: You can provide the pyc compile code of the libraries you are using and
putting them on the root of you software (or just stating where those imports
should happen) but I predict this will give you problems in the future due to
dependencies between different libraries. So, it's possible although I would
hardly considerate it a good solution for what it seems to me you are trying
to achieve.

