2016-01-22 49 views
4

所以對於一個Python包,你怎麼能夠從一個點安裝的軟件包命令行參數?下面是一個名爲mrbob的包的示例:如何才能啓用安裝PIP Python包shell命令行參數?

$ pip install mrbob 
$ mrbob DoSomethingFunction 

如何爲python包啓用命令行選項和新shell命令?

+0

如果包不支持此功能,你必須寫自己的CLI包裝。 –

+0

'mrbob'將不得不加入到系統PATH –

回答

3

隨着setuptools,定義console_script切入點:

setup(
    # other arguments here... 
    entry_points={ 
     'console_scripts': [ 
      'mrbob = my_package.some_module:main_func', 
     ] 
    } 
) 

有關詳細信息,請參閱setuptools文檔automatic script creation

隨着distutils,使用scripts

setup(..., 
     scripts=['scripts/mrbob'] 
    ) 

有關詳細信息,請參閱distutils文檔installing scripts

0

mrbob將被安裝在bin目錄 例如在我的情況下,它是:

/Library/Frameworks/Python.framework/Versions/2.7/bin/

只要這是你的$PATH你是好人。

+0

是「你」,「你」和「是」真的這麼難打出來? – dimo414