将Python模块转变为命令行工具

问:如何输入命令行就能执行python代码呢?

答:要将python模块转变为命令行工具只用在 setup.py 文件中添加参数entry_points

例如:

entry_points={
    'console_scripts': [ 'pycase = pycase.case:main' ] }

pycase 是自定义的参数,往后看

setup.py完整设置:

# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

"""
打包的用的setup必须引入,
"""

VERSION = '0.0.1'

setup(name='pycase',
        version=VERSION,
        description="a command line tool for camel case",
        long_description='a python command tool for camel case',
        classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
        keywords='pycase',
        author='Peng',
        author_email='[email protected]',
        license='MIT',
        packages=find_packages(),
        include_package_data=True,
        zip_safe=True,
        install_requires=[],
        entry_points={
             'console_scripts': ['pycase = pycase.case:main']
        }
)

猜你喜欢

转载自www.cnblogs.com/yuzhaoblog/p/12262943.html