1

I have a command line app that I want to deploy. The only problem is that to run it you have to run the python file like this: `

$python application.py <arguement>

`. I have seen other applications made in python that can run like this but would require this input

$application<arguement>

How can I make this possible?

Thanks in advance

0

1 Answer 1

1

Assuming you are doing it in bash (Linux) or similar, then have the first line of your source (.py) file as

#!/usr/bin/python

(depending on the location of your Python interpreter) or possibly

#!/usr/bin/env python

Then make the script executable

$ chmod +x foo

and make sure the directory is in your $PATH or explicitly specify the directory in your command e.g.

./foo
Sign up to request clarification or add additional context in comments.

8 Comments

OP is not asking about running python script in windows or linux and making the script as executable.
This is exactly what I want but what do you mean make it executable?
Executable files (programs) in Linux have a special flag (x) to dstinguish them. The chmod +x sets this flag so the system will attempt to execute the program if you ask it to. I suggest you go and read a tutorial on the Linux file system and how file permissions work.
Ok so it worked but I have to do ./<filename>.py. Is there a way to only have to do <filename> <arguement>? Also, I can only use it in the directory where my file is. Is there a way to make it usable everywhere?
Assuming you are using Linx/bash, make sure that the directory in which the Python scripts is on your $PATH (unix.stackexchange.com/questions/26047/…). That way, assuming there is nothing with the same name before it on your $PATH it should execute for you anywhere.
|