Ignorant new Linux/Ubuntu/StackOverflow user here.
I have my scripts for users to run in a path like /home/user/Projects/scripts/. If that is the pwd, I can invoke a script like this:
~/Projects/scripts$ python2.7 scriptname.py
(I am using python 2.7 because of legacy code.)
I want the users to not be forced to set the pwd to that directory to run scripts, just let them run from /home/user after logging in. Like this:
~$ python2.7 scriptname.py
Also, there are several directories with scripts, I am simplifying for this example.
I edited bash.rc to set PYTHONPATH to include that directory, then logged back in. The environment variable is set, but I can’t invoke the script from the home directory. I get
python2.7: can't open file 'script': [Errno2] No such file or directory
sys.path includes the path to the scripts directory. If I start python 2.7 from the home directory and import a script as a module, it finds it:
~$ python2.7
>> import script
>>
But I can’t get the command line to find it.
If I include the entire path on the command line, it works:
~$ python2.7 /home/user/Projects/scripts/scriptname.py
Should I be able to do this? What am I doing wrong?
Ed K is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.