Python脚本:shebang行(unix)问题

编程入门 行业动态 更新时间:2024-10-28 16:25:45
本文介绍了Python脚本:shebang行(unix)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过向本地服务器启动测试应用程序来体验Flask微框架.尝试运行我的代码 app.py 时,我不断收到错误消息:

I am trying to get a feel for the Flask microframework by launching a test application to local server. When trying to run my code, app.py, I keep getting the error message:

-bash: ./app.py: /flask/bin/python: bad interpreter: No such file or directory

这是基本代码(摘自此处)表示 app.py ,该代码位于我的todo-api目录中:

Here is the basic code (taken from here) for app.py, which lives in my todo-api directory:

#!/flask/bin/python from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello, World!" if __name__ == '__main__': app.run(debug=True)

我已经检查了python解释器的文件路径,它应该存在:

I've checked the file path to the python interpreter, and it should exist:

:bin $ pwd python Users/me/Documents/Python/todo-api/flask/bin

我已经按照教程学习了T;我尝试将shebang行更改为:

I have followed the tutorial to the T; I've tried changing the shebang line to:

#!/flask/bin/python2.x #!flask/bin/python #!/flask/bin/env python

但无济于事.我对bash并不了解,并且尝试查找正在发生的事情,但是对有类似问题的人的解决方案对我来说并不奏效;幕后有什么我不了解的事情吗?

But to no avail. I am not that knowledgeable about bash, and have tried looking up what is going on, but the solutions to folks with similar problems have not worked for me; is there something going on behind the scenes that I am not understanding?

推荐答案

Bash shebang期望到达解释器的绝对路径.因此,在您的情况下,您需要指定Python解释器的完整路径,即:

Bash shebangs expect an absolute path to the interpreter. So in your case you need to specify the full path to your Python interpreter i.e.:

#!/Users/me/Documents/Python/todo-api/flask/bin

您可能想研究/usr/bin/env python 的使用,以便能够使用用户的 $ PATH 环境变量中可用的解释器.参见 unix.stackexchange/questions/12736/how-does-usr-bin-env-know-which-program-to-use/12751#12751

You might want to investigate the use of /usr/bin/env python to be able to use the interpreter that is available in your user's $PATH environment variable. See unix.stackexchange/questions/12736/how-does-usr-bin-env-know-which-program-to-use/12751#12751

更多推荐

Python脚本:shebang行(unix)问题

本文发布于:2023-10-20 21:18:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1512156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Python   unix   shebang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!