[python] 转换python脚本程

发布时间:2019-09-17 07:49:59编辑:auto阅读(2325)

    方法1:

    freeze.py 来自python源码树.


    安装pythonbrew,可安装定制化的独立python环境(略)

    python trunk/Tools/freeze/freeze.py ./pkgdep.py

    之后make即可。

    问题:如果python脚本或依赖链的脚本中需要从.so中import,会出现问题。无数坑,放弃。

    具体可参看http://svn.python.org/projects/python/branches/pep-0384/Tools/freeze/README

    https://wiki.python.org/moin/Freeze(搜static)


    方法2:

    pyinstaller

    - 安装pythonbrew

    - pythonbrew install -v -C --with-dbmliborder=gdbm:bdb  -C --enable-unicode=ucs4 --universal ~/workspace/python/trunk

    http://www.thecodingforums.com/threads/got-undefined-symbol-_pyunicodeucs2_asdefaultencodedstring-onopensuse-11-1.699499/

    - pythonbrew switch trunk

    - 将依赖模块准备好:

    cd ~/.pythonbrew/pythons/Python-trunk/lib/python2.7/site-packages

    cp -a /usr/lib64/python2.7/site-packages/rpm .
    cp -a /usr/lib/python2.7/site-packages/urlgrabber .
    cp /usr/lib64/python2.7/lib-dynload/bz2.so ../lib-dynload/

    或从对应模块的源码安装模块:

    python setup.py install


    easy_install pip==1.2.1

    pip install pyinstaller


    pyinstaller -F ./helloworld.py

    完工。


    Reference:

    http://docs.python-guide.org/en/latest/shipping/freezing/

关键字