How to make my python script easy portable? or how to compile into binary with all module dependencies?

后端 未结 4 1721
谎友^
谎友^ 2020-12-24 15:32

Is there any way to compile python script into binary? I have one file python script which uses a lot of modules. What I would like is to have its copy on other machines (fr

4条回答
  •  悲&欢浪女
    2020-12-24 16:05

    cx_freeze will append your python scripts to a standalone Python loader and produce a directory containing the program, and shared library dependencies. You can then copy the resulting distribution to other machines independent of Python or your modules.

    $ cat hello.py 
    print "Hello, World!"
    $ ls dist/
    datetime.so  _heapq.so  hello  libpython2.6.so.1.0  readline.so
    $ cat hello.py 
    print "Hello, World!"
    $ cxfreeze hello.py 
    ...  ...
    $ ls dist/
    datetime.so  _heapq.so  hello  libpython2.6.so.1.0  readline.so
    $ ./dist/hello
    Hello, World!
    

    A better answer may be to create a PIP package that identifies these third modules as dependencies, so installation can be as simple as "pip install mypackage; ./package"

提交回复
热议问题