分发可执行模块 [英] Distribute executable module

查看:79
本文介绍了分发可执行模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个程序,该程序由可执行的程序包(即两个文件x/__init__.pyx/__main__.py)组成,因此,如果程序包位于python路径中,则可以使用python -m x执行该程序.

I developed a program consisting of a package which is executable (i.e. two files x/__init__.py and x/__main__.py), so I can execute it using python -m x, if the package resides in the python path.

我从未尝试分发Python软件包/模块,并且在该领域还没有任何经验(尚未)……我已经注意到有很多不同的系统,现在我有三个问题:

I never tried to distribute Python packages/modules and I don't have any experience in that field (yet)... I already noticed that there are many different systems and now I have three questions:

  1. 哪个系统适合使用Python 3(.2)程序?分发? distutils? setuptools?

  1. Which system is appropiate for a Python 3(.2) program? distribute? distutils? setuptools?

如何在不使用python -m …麻烦的情况下直接向执行模块的发行版中添加某种包装脚本",以便用户只需键入x(当然,实际名称要多一些)在外壳上是唯一的:).

How can I add kind of a "wrapper script" to the distribution that executes the module directly without the hassle with python -m … so that the user can just type x (of course the actual name is a bit more unique :) on the shell.

我该如何以2.与平台无关的方式进行操作?

How can I do 2. in a platfom-independent way?

谢谢! :)

推荐答案

  1. 使用distributesetuptools,前者是后者的分支,具有一些改进和更好的文档.

  1. Use either distribute or setuptools, the former is a fork of the latter, with some improvements and better documentation. Either one is a big step up from distutils, which is part of the python standard library.

您需要一个控制台脚本,为其定义一个入口点:

You want a console script, for which you define an entry point:

entry_points = {
    'console_scripts': [
        'foo = my_package.some_module:main_func',
        'bar = other_module:some_func',
    ],

其中foobar是可以在命令行上调用的脚本.指示的函数将以sys.argv[1:]作为第一个也是唯一的参数来调用.

where foo and bar would be scripts that you can call on the command line. The indicated function will be called with sys.argv[1:] as the first and only argument.

让安装工具来解决这个问题;在Windows上可以正常使用. :-)

Let the installation tools take care of that; it works fine on Windows. :-)

这篇关于分发可执行模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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