Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile python script in linux

So I have a python script that relies on a couple modules. Specifically pexpect and pyinoitify. I know you can compile a python script into a .exe in windows, but is there something relatively equivalent in linux? I don't care about it being a binary, I'd just like to be able to distribute my script without requiring the separate installation of pexpect and pyinotify. Is that possible/worthwhile?

like image 772
Falmarri Avatar asked Sep 08 '10 20:09

Falmarri


People also ask

How do I compile a Python script in Linux?

You can also automatically compile all Python files using the compileall module. You can do it from the shell prompt by running compileall.py and providing the path of the directory containing the Python files to compile: monty@python:~/python$ python -m compileall .

How do I compile and run a Python script?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!


1 Answers

cx_Freeze is a cross-platform way to "freeze" a Python script into standalone binary form. According to their site:

cx_Freeze is a set of scripts and modules for freezing Python scripts into executables in much the same way that py2exe and py2app do. Unlike these two tools, cx_Freeze is cross platform and should work on any platform that Python itself works on. It requires Python 2.3 or higher since it makes use of the zip import facility which was introduced in that version.

like image 146
Katriel Avatar answered Sep 30 '22 09:09

Katriel