Calling a python script from command line without typing “python” first

前端 未结 6 616
暖寄归人
暖寄归人 2020-11-29 10:27

Question: In command line, how do I call a python script without having to type python in front of the script\'s name? Is this even possible?


Info

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 10:55

    Another way to do this would be to package your python script.

    Then all you would have to do is run $ pip install package-name and simply running $ package-name from any directory would execute your python script.

    I would recommend this method since it enables you to quickly share/install/use/remove your python script.

    I wrote a simple script QuickPackage that can instantly create and upload python package for your awesome script by just entering the path of your python script.

    Example:

    $ pip install quickpackage
    

    Usage :

    Usage Simply run quickpackage and enter the path of your python script.

    Example:

    ❯ quickpackage                                                    
    Enter name: quickpackage
    Enter version: 1.1
    Enter description: Instantly create and upload python package for your script
    Enter github url: https://github.com/yask123/quick-package
    enter author: Yask Srivastava
    Enter email: yask123@gmail.com
    Path of python script file: run.py
    running register
    ....
    running upload
    Submitting dist/quickpackage-1.1.tar.gz to https://pypi.python.org/pypi
    Server response (200): OK
    

    Now simply execute your script by running$ quickpackage (In this case)

提交回复
热议问题