简体   繁体   中英

python program as a command-line tool in linux

This is my program folder example:

program_name
  main.py
  lib.py
  options.py

I want to launch it like this: program_name args [options] from anywhere in my Linux os.

Now I already did all the args/options stuff inside my code but actually, I have to cd into the folder and launch the file like python3 main.py args [options]

There is a way to do it? Please don't say things like chmod +x #/bin/python for./filename or alias stuff related I read all those articles. I need it to works on boots too. I studied something for program paths like /usr/local but I never tried. Did anyone never try that? Or have any solution?

I don't know if that is what you are searching for, but you could just symlink it to your /usr/local/bin like you said, it's safe. Here's some explainations about where you should symlink in the answer of this post https://unix.stackexchange.com/questions/116508/adding-to-path-vs-linking-from-bin

I also don't understand why an alias in your.bashrc can't do the trick, it would be easier, but you probably have your reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM