python - Python script with executable permission says "Command Not Found"
问题描述
I have a python script abc.py. Inside a shell script file, I call it ./abc.py
Inside abc.py, at the top, I have #!/usr/bin/python
test -x abc.py && echo true || echo false
return true
On executing the shell script, it says ./abc.py: Command not found.
It works if I call it as python ./abc.py
instead of just ./abc.py
The issue is only with this abc.py file that I created today. The older python scripts in the same directory with different purpose and names work without any issue.
I have referred the correct path of the file BTW. What could be the issue?
解决方案
In tcsh
, this happens when the interpreter is invalid:
$ cat foo
#!/invalid
$ tcsh -c './foo'
./foo: Command not found.
$ bash -c './foo'
bash: ./foo: /invalid: bad interpreter: No such file or directory
This could be for several reasons. Perhaps your path is wrong for your system:
% type python
python is /usr/local/bin/python
in this case the script needs to start with #!/usr/local/bin/python
instead.
Alternatively, the script could have Windows line endings (carriage returns):
$ cat -v foo
#!/usr/bin/python^M
...^M
In this case, save it with Unix line endings instead.
推荐阅读
- python - 返回给定列表的所有可能子集返回错误答案
- pyspark - 如何使用 pyspark 和 jupyter 获得评估指标?
- python - 在独立脚本中使用 Django 模型 - 网站未更新
- xaml - Xamarin bind to another element from within a listview itemtemplate
- c# - asp.net core 中的授权类型
- python - 使用一个小的声音文件来创作一首歌曲
- javascript - Nativescript - 使用 http 模块上传图片
- java - Java从解析的html表中获取数组
- c# - 为什么我的 do While 循环会导致无限循环?
- git - git推送到远程分支问题