how make python command line apps accessible globally?

Tokyo Developer

I wrote a command-line app using python. the problem is I want the to user can use the command globally after installed the command-line . I wrote the command-line, I published the package but I don't know how to make this package globally available for users as system commands.

Example :

pip install forosi

and after that user can globally run this command from everywhere they want . like :

forosi help
Mustafa Quraish

I'm going to assume you have the main file you are supposed to run in src/forosi.py in your package directory, but you should be able to adapt this if it's different.

  • First, you want to rename the script to forosi, without the .py extension.

  • Second, at the top of the file (now called forosi) add the following:

#!/usr/bin/env python3

... rest of file...
  • In your setup.py for the package, you need to use the scripts option.
setuptools.setup(
    ...
    scripts=['src/forosi'],
    ...
)

This is the method that required minimal refactoring of your code. If you happen to have a main() function in one of your python files which is the entrypoint of the script, you can just add the following into your setup.py instead of the above:

setup(
    ...
    entry_points = {
        'console_scripts': ['src.forosi:main'],
    }
    ...
)

In either case, to build the package locally, run

python3 setup.py bdist_wheel

This will create a wheel file in the dist/ directory called package_name-version-<info>-.whl. This is the official distribution for pypi packages.

To install this package, run:

pip3 install dist/package_name-version-<info>-.whl

or if you only have one version in the dist folder, just

pip3 install dist/*

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make a variable globally accessible in Prestashop

How to make a class accessible globally in a Laravel application?

How to make dotnet globally accessible in windows powershell?

How do I download documentation and make it accessible from the command line?

How do I make the dataframe within an R function globally accessible?

How to make new data type globally accessible in Swift?

How to make all the commands which come with git available globally from the windows command line?

How to make globally callable python program?

Codeigniter 4 /CI4/ Using database to keep site configurations/ How to make key and value accessible globally

How do I globally store a trait object to make it accessible to a C API callback?

How to make globally accessible info through Context API to be saved locally to persist across a refresh?

Lint extension in brackets is not being able to find it how to make php from wamp globally accessible

How to make python process inputs from command line?

How to make a GUI for command-line application in Python?

how do I make a python program write directly to the command line?

How to make a for loop in command line?

How to run Chrome apps via command line?

Command line "launch path not accessible"

Ember.js: make current user globally accessible

Vue: automatic rendering some components and make theirs methods accessible globally

Angular JS - Make service globally accessible from controllers and view

Make custom js file globally accessible in NUXT app

Make Python script globally executable

how to make the command line screen follow the curser?

How to make a command line program in C

How to make a package executable from the command line?

How to make a Nodejs distributable command line application

How to make a Command Line application with WebRTC in Linux?

How to make a line of directories with one command?

TOP Ranking

HotTag

Archive