2

I have a python script called script.py that takes in arguments and gives the output. Every time I use the script, I copy it to local working directory and then execute it as python script.py --arg1=a. I was wondering if there is a way to call the python function in local working directory without copying it, like how u can copy u c++ build files to /usr/local/bin and call it from anywhere.

Thanks.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Mc Missile
  • 715
  • 11
  • 25
  • You can manipulate sys.path in python script to expose libs for import into Python environment – skullgoblet1089 Mar 04 '19 at 03:44
  • Possible duplicate of [Make Python script globally executable](https://stackoverflow.com/questions/24295131/make-python-script-globally-executable) – Klaus D. Mar 04 '19 at 03:47

2 Answers2

2

You can try this steps:

  1. put #!/usr/bin/python on the first line of your script.

  2. making it executable by using chmod +x script.py

  3. Move it to /usr/bin directory

then try to execute script.py in the terminal.

Jethro Sandoval
  • 266
  • 1
  • 7
0

Add a shebang to the script - Should I put #! (shebang) in Python scripts, and what form should it take?

#!/usr/bin/env python3
print('hello')

Make it executable

chmod +x script.py

Then you can execute it from the local (or any other) directory

./script.py

If you want to be globally available, you need to edit your PATH

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245