Let's say I want to use a shell script to run a python file, called test.py, which is in a directory called Test in my home directory. I tried the following code, which does not work:
#!/bin/bash
echo "Starting."
module load gcc/4.8.2
module load python/3.4.1
echo "Modules loaded."
$HOME/Test/test.py
exit 0
I do not believe that how I am trying to run the program ($HOME/Test/test.py) works. I have not been able to determine how to do this, despite searching for a long time. Any help would be appreciated.
1 Answer 1
This is likely one of the following, or it may be a combination of both.
The python script is not executable. Fix with:
chmod u+x $HOME/Test/test.py
The script does not start with a #! line pointing to python. Fix that by making this the first line of test.py:
#!/usr/bin/env python
You can also use a full path instead of using /usr/bin/env to use $PATH to resolve the name.
#!/usr/local/bin/python
2 Comments
/usr/bin/env will just resolve whatever is after it to some full path, so if you use python as python3, then yes you would do that. You can also use a full path to the interpreter instead, such as #!/usr/bin/python3.