我感谢任何愿意尝试帮助我解决此问题的人。我目前正在上一门机器学习课程,但我一直无法尝试弄清楚应该是什么简单安装。我会尽力解释,但是我是新手,请耐心等待。
我正在使用Terminal运行一个非常基本的Flask应用程序。在终端中,我能够安装Flask。我在终端中输入了以下两个命令:
运行flask之后,我现在收到一条错误消息,阻止我继续前进: “错误:无法导入“你好”。
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
上面是我在Sublime中使用的代码,应该允许返回“ Hello,World!”
该命令应该在URL地址上运行,但是它只是告诉我它将不会导入“ hello”。 hello.py是具有代码的Sublime保存文件。
如果这听起来令人困惑,我深表歉意,因为我完全感到困惑,甚至都不知道该如何正确表达我的问题。如果有人可以帮助我,我将尽力提供尽可能多的信息,但是如果有人熟悉的话,我正在参加的机器学习课程就是Siraj Raval。从字面上看,这是引言中的第二个视频,因此,您可以想象我对尝试理解这一点已经遇到了严重的问题,对此感到非常沮丧。感谢您的阅读,非常感谢您的帮助!
如果有帮助,这里是我使用的命令提示符的确切顺序>>
Last login: Sun Sep 22 17:25:19 on ttys000
Justins-MacBook-Pro:~ justinunion$ mkdir myproject
mkdir: myproject: File exists
Justins-MacBook-Pro:~ justinunion$ cd myproject/
Justins-MacBook-Pro:myproject justinunion$ python3 -m venv venv
Justins-MacBook-Pro:myproject justinunion$ . venv/bin/activate
(venv) Justins-MacBook-Pro:myproject justinunion$ pip3 install flask
Requirement already satisfied: flask in ./venv/lib/python3.7/site-packages (1.1.1)
Requirement already satisfied: click>=5.1 in ./venv/lib/python3.7/site-packages (from flask) (7.0)
Requirement already satisfied: itsdangerous>=0.24 in ./venv/lib/python3.7/site-packages (from flask) (1.1.0)
Requirement already satisfied: Werkzeug>=0.15 in ./venv/lib/python3.7/site-packages (from flask) (0.16.0)
Requirement already satisfied: Jinja2>=2.10.1 in ./venv/lib/python3.7/site-packages (from flask) (2.10.1)
Requirement already satisfied: MarkupSafe>=0.23 in ./venv/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)
(venv) Justins-MacBook-Pro:myproject justinunion$ sublime
-bash: sublime: command not found
(venv) Justins-MacBook-Pro:myproject justinunion$ ls
venv
(venv) Justins-MacBook-Pro:myproject justinunion$ sublime hello.py
-bash: sublime: command not found
(venv) Justins-MacBook-Pro:myproject justinunion$ ls
venv
(venv) Justins-MacBook-Pro:myproject justinunion$ export FLASK_APP=hello.py
(venv) Justins-MacBook-Pro:myproject justinunion$ flask run
* Serving Flask app "hello.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: Could not import "hello".
(venv) Justins-MacBook-Pro:myproject justinunion$