以前用的是pycharm的专业版,后来搞得破解不了了,花了几个小时研究了一下怎么用VScode
来搭建python开发的环境。
开始之前:
yarn
、npm
)//安装pipienv
pip install pipenv
//依赖包安转初始化( 首次的话会生成一个Pipfile
的文件,类似前端的package.json
)
pipenv install
//安装flask框架
pipenv install flask
//开启编译环境(类似yarn run dev
)
pipenv shell
app.py
文件 (代码如下)from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello111 2222World!
'
if __name__ == '__main__':
app.run(debug=True)
附录:
launch.json的基本配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: init",
"type": "python",
"request": "launch",
"module": "flask",
"program": "${file}",
"env": {
"FLASK_APP": "${workspaceFolder}/exercise-demo/__init__.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: flask_mysql",
"type": "python",
"request": "launch",
"module": "flask",
"program": "${workspaceFolder}/exercise-demo/flask_mysql.py",
"env": {
"FLASK_APP": "${workspaceFolder}/exercise-demo/flask_mysql.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
settings.json配置
{
"python.pythonPath": "C:\\Users\\Administrator\\.virtualenvs\\Python-flask-web-Pl4E3FQd\\Scripts\\python.exe",
"python.testing.pyTestArgs": [
"exercise-demo"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pyTestEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}