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.

2
  • You can manipulate sys.path in python script to expose libs for import into Python environment Commented Mar 4, 2019 at 3:44
  • Possible duplicate of Make Python script globally executable Commented Mar 4, 2019 at 3:47

2 Answers 2

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.

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

1 Comment

/usr/bin probably not the best spot. Better to edit the PATH to add a $HOME/bin, for example
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.