Htechno
Htechno

Reputation: 6127

Python freeze.py generated bin doesn't run

I need to run a Python 2.7 script into a client critical machine, so I have permission to install nothing, and when I say nothing I mean nothing even into local dirs, so the solution I found is to pass him the script as a binary created with the batteries-included tool "freeze.py" http://wiki.python.org/moin/Freeze , and I also added required and unembedable .so libraries into the same folder (_io.so, _heapd.so, ...) and give them executable permisions.

But when I try to execute the binary I get:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 562, in <module>
  File "/usr/lib/python2.7/site.py", line 544, in main
  File "/usr/lib/python2.7/site.py", line 271, in addusersitepackages
  File "/usr/lib/python2.7/site.py", line 246, in getusersitepackages
  File "/usr/lib/python2.7/site.py", line 236, in getuserbase
  File "/usr/lib/python2.7/sysconfig.py", line 558, in get_config_var
  File "/usr/lib/python2.7/sysconfig.py", line 457, in get_config_vars
  File "/usr/lib/python2.7/sysconfig.py", line 310, in _init_posix
IOError: invalid Python installation: unable to open /usr/lib/python2.7/config/Makefile (No such file or directory)

I guess it's trying to find some code into default Python 2.7, but it's absurd because the goal of freeze is to be executable into environments with no Python, from the docs:

If you want to write Python, but you don't know if your clients have Python installed, use this!

So... what the hell I'm doing wrong?

P.S.: I tryed with the hello.py example and results in the same error, it's this tool definetively outdated?

Upvotes: 2

Views: 1667

Answers (1)

Frank
Frank

Reputation: 31

I patched Python-2.7.2/Tools/freeze/makefreeze.py from the source package like this:

--- orig/Python-2.7.2/Tools/freeze/makefreeze.py    2011-06-11 17:46:28.000000000 +0200
+++ 2.7.2/Python-2.7.2/Tools/freeze/makefreeze.py   2011-11-15 18:18:33.632177119 +0100
@@ -23,6 +23,7 @@
 """ + ((not __debug__ and """
         Py_OptimizeFlag++;
 """) or "")  + """
+        Py_NoSiteFlag = 1;
         PyImport_FrozenModules = _PyImport_FrozenModules;
         return Py_FrozenMain(argc, argv);
 }

-> I added Py_NoSiteFlag = 1; to the frozen main(), so the implicit import site of the python interpreter on startup will be disabled.

Frank

Upvotes: 3

Related Questions