我正在尝试通过向本地服务器启动测试应用程序来体验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)问题
发布评论