I am in Ubuntu 16.4. I have just written a program that can be executed using the command(assuming i'm in the correct directory) ./Main.py -h
However I want this to be distributable, so that you can use it from the command line like nmap or youtube-dl. My idea was to put an alias is .bashrc. This had two problems. One was that I couldn't have the options(-h) in the command if there was a command after it, so it changed your directory. Second I don't know what directory the users would install it in. So even if I appended the alias to .bashrc I wouldn't know what directory it was installed in. I tried to fix this issue by copying the files to their home directory but this gave me an error that said Permission Denied(while running the program) as it needs to be able to write to files. I tryed for a while to fix this but in the end they needed to run it as root and that shouldn't be necessary. So how should I install this so that it can be used like a regular command line tool?
Asked
Active
Viewed 61 times
0
Peyto
- 105
- 7
-
Possible duplicate of [How can I distribute python programs?](http://stackoverflow.com/questions/1558385/how-can-i-distribute-python-programs) – Ghilas BELHADJ May 19 '17 at 22:27
1 Answers
0
Normal convention for command line programs is to place them on the default path, which is to say in one of the directories represented by the $PATH environment variable. There is also a default on various systems.
This way, when you enter a command, your shell will attempt to find a match in one of these directories, and you can omit the ./ part of the invocation.
Try the command echo $PATH to see what the path directories are on your particular system. /usr/local/bin is usually a good choice for a custom script.
Since you are using Python, you will also want to set it up as an executable script, which is a pretty common thing to do.
Good luck!