Python 如何在 Windows 上安装 Flask?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17917254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install Flask on Windows?
提问by Nardrek
I have a project to do for after create a webpage that display the latest weather from my CSV file.
在创建一个网页后,我有一个项目要做,该网页显示我的 CSV 文件中的最新天气。
I would like some details how to do it (don't really get the http://flask.pocoo.org/docs/installation/#installationinstallation setup)
我想要一些如何做的细节(不要真正得到http://flask.pocoo.org/docs/installation/#installation安装设置)
Can anyone mind explain me how to do it simply?
谁能介意解释我如何简单地做到这一点?
Thanks.
谢谢。
I'm running on Windows 7, with the Windows Powershell.
我在 Windows 7 上运行,使用 Windows Powershell。
采纳答案by Uku Loskit
Install pip as described here: How do I install pip on Windows?
按照此处所述安装 pip:如何在 Windows 上安装 pip?
Then do
然后做
pip install flask
That installation tutorial is a bit misleading, it refers to actually running it in a production environment.
那个安装教程有点误导,它指的是实际在生产环境中运行它。
回答by Priyansh
On Windows, installation of easy_install is a little bit trickier, but still quite easy. The easiest way to do it is to download the distribute_setup.py file and run it. The easiest way to run the file is to open your downloads folder and double-click on the file.
在 Windows 上,easy_install 的安装有点棘手,但仍然很容易。最简单的方法是下载distribute_setup.py 文件并运行它。运行该文件的最简单方法是打开您的下载文件夹并双击该文件。
Next, add the easy_install command and other Python scripts to the command search path, by adding your Python installation's Scripts folder to the PATH environment variable. To do that, right-click on the “Computer” icon on the Desktop or in the Start menu, and choose “Properties”. Then click on “Advanced System settings” (in Windows XP, click on the “Advanced” tab instead). Then click on the “Environment variables” button. Finally, double-click on the “Path” variable in the “System variables” section, and add the path of your Python interpreter's Scripts folder. Be sure to delimit it from existing values with a semicolon. Assuming you are using Python 2.7 on the default path, add the following value:
接下来,通过将 Python 安装的 Scripts 文件夹添加到 PATH 环境变量,将 easy_install 命令和其他 Python 脚本添加到命令搜索路径。为此,请右键单击桌面或开始菜单中的“计算机”图标,然后选择“属性”。然后单击“高级系统设置”(在 Windows XP 中,改为单击“高级”选项卡)。然后单击“环境变量”按钮。最后,双击“系统变量”部分中的“路径”变量,并添加 Python 解释器的 Scripts 文件夹的路径。请务必使用分号将其与现有值分隔开。假设您在默认路径上使用 Python 2.7,请添加以下值:
;C:\Python27\Scripts And you are done! To check that it worked, open the Command Prompt and execute easy_install. If you have User Account Control enabled on Windows Vista or Windows 7, it should prompt you for administrator privileges.
;C:\Python27\Scripts 大功告成!要检查它是否有效,请打开命令提示符并执行 easy_install。如果您在 Windows Vista 或 Windows 7 上启用了用户帐户控制,它应该会提示您输入管理员权限。
Now that you have easy_install, you can use it to install pip:
现在你有了 easy_install,你可以用它来安装 pip:
easy_install pip
easy_install pip
回答by Anum Sheraz
heres a step by step procedure (assuming you've already installed python):
继承人一步一步的过程(假设你已经安装了python):
- first install chocolatey:
- 首先安装巧克力:
open terminal (Run as Administrator) and type in the command line:
打开终端(以管理员身份运行)并在命令行中输入:
C:/> @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
C:/> @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString(' https://chocolatey.org/install.ps1'))" && SET PATH=%PATH% ;%ALLUSERSPROFILE%\chocolatey\bin
it will take some time to get chocolatey installed on your machine. sit back n relax...
在您的机器上安装巧克力需要一些时间。坐下来放松...
now install pip. type in terminal cinst easy.install pip
now type in terminal: pip install flask
现在安装pip。输入终端cinst easy.install pip
现在输入终端:pip install flask
YOU'RE DONE !!! Tested on Win 8.1 with Python 2.7
你完成了 !!!在 Win 8.1 和 Python 2.7 上测试
回答by imbond
First install flask using pip,
首先使用pip安装flask,
pip install Flask
* If pip is not installed then install pip
* 如果没有安装 pip 则安装 pip
Then copy below program (hello.py)
然后复制下面的程序(hello.py)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
Now, run the program
现在,运行程序
python hello.py
Running on http://127.0.0.1:5000/(Press CTRL+C to quit)
Just copy paste the above address line in your browser.
在http://127.0.0.1:5000/ 上运行(按 CTRL+C 退出)
只需将上面的地址行复制粘贴到浏览器中即可。
Reference: http://flask.pocoo.org/
回答by Manjot Singh
I have windows 10 and pythonv3.5. @uku answer is correct. however, problem I was facing is that where are python scripts which are to be added in environment variable. So I found out that we need to add
我有 Windows 10 和 pythonv3.5。@uku 答案是正确的。但是,我面临的问题是要添加到环境变量中的 python 脚本在哪里。所以我发现我们需要添加
C:\Users\\AppData\Local\Programs\Python\Python35\Scripts
C:\Users\\AppData\Local\Programs\Python\Python35\Scripts
above location as environment variable. If it still doesnot work search for python in C Drive then find out script locations.
以上位置作为环境变量。如果它仍然不起作用在 C 驱动器中搜索 python 然后找出脚本位置。
回答by Ansi
First: I assumed you already have Python 2.7or 3.4installed.
首先:我假设您已经安装了Python 2.7或 3.4。
1: In the Control Panel, open the System option (alternately, you can right-click on My Computer and select Properties). Select the “Advanced system settings” link.
1:在控制面板中,打开系统选项(或者,您可以右键单击我的电脑并选择属性)。选择“高级系统设置”链接。
In the System Properties dialog, click “Environment Variables”.
In the Environment Variables dialog, click the New button underneath the “System variables” section.
if someone is there that above is not working, then kindly append to your PATH with the C:\Python27 then it should surely work. C:\Python27\Scripts
Run this command (Windows cmd terminal): pip install virtualenv
If you already have pip, you can upgrade them by running:
pip install --upgrade pip setuptools
Create your project. Then, run virtualenv flask
在“系统属性”对话框中,单击“环境变量”。
在“环境变量”对话框中,单击“系统变量”部分下方的“新建”按钮。
如果有人在那里上面不起作用,那么请将 C:\Python27 附加到您的 PATH 中,那么它肯定可以工作。C:\Python27\Scripts
运行此命令(Windows cmd 终端):pip install virtualenv
如果你已经有 pip,你可以通过运行来升级它们:
pip install --upgrade pip setuptools
创建您的项目。然后,运行virtualenv 烧瓶
回答by Ben J'o
Assuming you are a PyCharmUser, its pretty easy to install FlaskThis will help users without shell pip access also.
假设您是PyCharm用户,安装Flask非常容易 这也将帮助没有 shell pip 访问权限的用户。
- Open Settings(Ctrl+Alt+s) >>
- Goto Project Interpreter>>
- Double click pip>> Search for flask
- Select and click Install Package ( Check Install to site users if intending to use Flask for this project alone Done!!!
- 打开设置(Ctrl+Alt+s)>>
- 转到项目解释器>>
- 双击pip>> 搜索烧瓶
- 选择并单击安装包(如果打算将 Flask 单独用于此项目,请选中安装到站点用户 完成!!!
Cases in which flask is not shown in pip: Open Manage Repository>> Add(+) >> Add this following url
pip 中未显示烧瓶的情况:打开管理存储库>>添加(+)>>添加以下网址
Now back to pip, it will show related packages of flask,
现在回到pip,它会显示flask的相关包,
- select flask>>
- install package>>
- 选择烧瓶>>
- 安装包>>
Voila!!!
瞧!!!
回答by Sufiyan
If You are using windows then go to python installation path like.
如果您使用的是 Windows,则转到 python 安装路径。
D:\Python37\Scripts>pip install Flask
D:\Python37\Scripts>pip install Flask
it take some movement to download the package.
下载软件包需要一些动作。
回答by mujahid Malik-arain
you are a PyCharm User, its good easy to install Flask First open the pycharm press Open Settings(Ctrl+Alt+s) Goto Project Interpreter
您是 PyCharm 用户,安装 Flask 非常容易 首先打开 pycharm 按 Open Settings(Ctrl+Alt+s) 转到 Project Interpreter
Double click pip>>
search bar (top of page) you search the flask and click install package
such Cases in which flask is not shown in pip: Open Manage Repository>> Add(+) >> Add this following url
在 pip 中未显示烧瓶的情况:打开管理存储库>>添加(+)>>添加以下网址
https://www.palletsprojects.com/p/flask/
Now back to pip, it will show related packages of flask,
现在回到pip,它会显示flask的相关包,
select flask>>
install package
回答by Dulangi_Kanchana
https://www.youtube.com/watch?v=QjtW-wnXlUY&t=38s
https://www.youtube.com/watch?v=QjtW-wnXlUY&t=38s
Follow as in the url
按照网址
This is how i do : 1) create an app.py in Sublime Text or Pycharm, or whatever the ide, and in that app.py have this code
这就是我的做法:1)在 Sublime Text 或 Pycharm 或任何 ide 中创建一个 app.py,并在该 app.py 中有此代码
from flask import Flask
app = Flask(__name__)
@app.route('/')
def helloWorld():
return'<h1>Hello!</h1>'
This is a very basic program to printout a hello , to test flask is working.I would advise to create app.py in a new folder, then locate where the folder is on command prompt enter image description heretype in these line of codes on command prompt
这是一个非常基本的程序,用于打印 hello ,以测试烧瓶是否正常工作。我建议在新文件夹中创建 app.py,然后在命令提示符下找到该文件夹所在的位置在 此处输入图像描述在这些代码行中键入命令提示符
>py -m venv env
>env\Scripts\activate
>pip install flask
Then
然后
>set FLASK_APP=app.py
>flask run
Then press enter all will work
The name of my file is app.py, give the relevant name as per your file in code line
然后按回车所有将工作
我的文件的名称是app.py,在代码行中根据您的文件给出相关名称
set FLASK_APP=app.py
Also if your python path is not set, in windows python is in AppData folder its hidden, so first have to view it and set the correct path under environment variables. This is how you reach environment variables
Control panel ->> system and security ->> system ->> advanced system setting
Then in system properties you get environment variables
另外,如果你的python路径没有设置,在windows中python隐藏在AppData文件夹中,所以首先必须查看它并在环境变量下设置正确的路径。这是您访问环境变量的方式
控制面板 ->> 系统和安全 ->> 系统 ->> 高级系统设置 然后在系统属性中您可以获得环境变量