I keep getting shell ERROR: python3: can't open file 'path/to/service.py': [Errno 2] No such file or directory
**globals.py**
#contains a dictionary:
SERVICE_MAP = {
'test': '~/path/to/service.py',
'test2': '$HOME/path/to/service.py',
'test3': '/full/path/to/service.py',
}
I have tried all the above forms of paths to the services. and the method of retrieval is:
**launch.sh**
function get_service() {
python3 -c "import common.globals as gbl; print(gbl.SERVICE_MAP['$1'])"
}
And then call:
**launch.sh**
service=$(get_service "test") # get service "test"
echo $service #Output: is what it should be... "path/to/service.py"
# but when I now do:
python3 $service
#or
python3 "$service"
Output is always:
python3: can't open file '/path/to/service.py': [Errno 2] No such file or directory
What am I doing wrong here?
Instead of using the full path in the globals.py
I put the relative path:
SERVICE_MAP = {
'test': '/rel/path/to/service.py',
}
And in my launch.sh
script I prepend $HOME
:
function get_service() {
python3 -c "import common.globals as gbl; print(gbl.SERVICE_MAP['$1'])"
}
python3 "$HOME$(get_service "test")"
I like this best because the $HOME
user may change someday... Answered my own question, thanks for looking!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.