Python 模块分发安装可执行文件到路径

Python module distribution installs executable to path

过去我在 PyPI 上看到 Python 模块分发,当你使用 pip 安装它们时,它安装了一个可执行文件到路径,不幸的是我找不到这样的了。

我想知道这怎么可能。你会在你的 setup.py 中这样做吗?你能让它在多个平台上工作吗?

A link 一个模块这样做也会非常有帮助。

我不是在谈论将 python 模块安装到 python 路径,而是将 可执行文件安装到系统路径

看看http://python-packaging.readthedocs.org/en/latest/command-line-scripts.html

The scripts Keyword Argument

The first approach is to write your script in a separate file, such as you might write a shell script.:

funniest/
     funniest/
         __init__.py
         ...
     setup.py
     bin/
         funniest-joke

... The funniest-joke script just looks like this:

#!/usr/bin/env python

import funniest print funniest.joke()

Then we can declare the script in setup() like this:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ... ) 

When we install the package, setuptools will copy the script to our PATH and make it available for general use.