Python freeze.py generated bin doesn't run

本秂侑毒 提交于 2019-12-07 23:46:20

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/6486414/python-freeze-py-generated-bin-doesnt-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!