Python Frozen.py生成的bin无法运行 [英] Python freeze.py generated bin doesn't run

查看:113
本文介绍了Python Frozen.py生成的bin无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在客户端关键计算机上运行Python 2.7脚本,因此我无权安装任何内容,并且当我什么也不说时,什至对本地目录也没有任何意义,因此我找到的解决方案是将脚本传递给他使用包含电池的工具"freeze.py"创建的二进制文件 http://wiki.python.org/moin/Freeze ,我还将必需和不可嵌入的.so库添加到同一文件夹(_io.so,_heapd.so等)中,并为它们提供可执行的权限.

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)

我想它正在尝试在默认的Python 2.7中找到一些代码,但这是荒谬的,因为冻结的目标是要从文档中执行到没有Python的环境中:

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:

如果您想编写Python,但是您 不知道你的客户是否有Python 安装好了,用这个!

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 .:我尝试使用hello.py示例并导致相同的错误,这是该工具明显过时的吗?

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

推荐答案

我从源代码包中修补了Python-2.7.2/Tools/freeze/makefreeze.py,如下所示:

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);
 }

->我在冻结的main()中添加了Py_NoSiteFlag = 1;,因此启动时python解释器的隐式import site将被禁用.

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

坦率

这篇关于Python Frozen.py生成的bin无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆