配置 VScode for Python 3.7.3
*前言
个人来说,vscode写python,轻量化且方便,是个不错的选择。
此文只是记录个人 Vscode 配置 python 3.7的过程。
通过阅读VScode官方文档得知,要在VSCODE中配置python环境,需要:
-1.Vscode中微软官方发布的python 拓展插件
-2.安装python 3以上版本
-3. 如果要用python用于数据科学目的,还需要下载安装Anaconda。
Prerequisites
To successfully complete this tutorial, complete the following requirements:
- Install the Python extension for VS Code. For details on installing extensions, see Extension marketplace. The Python extension is named Python and published by Microsoft.
- Install a version of Python 3 (for which this tutorial is written). Options include:
- (All operating systems) A download from python.org; you can typically use the Download Python 3.7.3 button that appears first on the page (or whatever is the latest version).
- (Linux) The built-in Python 3 installation works well, but to install other Python packages you must install
pip
withget-pip.py
.- (macOS) An installation through Homebrew on macOS using
brew install python3
(the system install of Python on macOS is not supported).- (All operating systems) A download from Anaconda (for data science purposes).
Note You can use the
py -0
command in the integrated terminal to view the versions of python installed on your machine. The default interpreter is identified by an asterisk (*).
步骤简介:
1.下载 并安装VS code 、Python
-
安装Python拓展
-
setting.json
中python path
修改成 ''c:xxx\Python37\python.exe
''。
这一步随着新版本(2019-5-15以后)发布,vscode已经能自动识别系统中安装的python,不用手动添加路径了。
4.配置工作区
步骤详解
1.下载 并安装vs code 、python
1.1下载并安装 VS code:[Visual Studio Code](https://code.visualstudio.com/
image.png1.2 下载并安装Python:https://www.python.org/downloads/windows/
写这步骤时,Python 为3.7.3 版本
点Customize installation
自定义安装
并将python安装路径改成:C:\Python37\
方便下一步的配置
或自定义安装,记得选上 pip,一般默认是选上的
image.png
1.3 配置环境变量
image.png
把
C:\python37\
(python.exe所在文件夹)C:\python37\Scripts
(pip所在文件夹)添加到环境变量中 image.png image.png
顺便用pip安装pylint
打开cmd
输入pip install pylint
2.VScode里面安装python插件和相应拓展
image.png3.在VS code目录点击 File>Preference>Settings (2019新版本无需进行)
或
快捷键 Ctrl+;打开Settings.json
文件
这一步随着新版本(2019-5-15以后)发布,vscode已经能自动识别系统中安装的python,不用手动添加路径了。
image.png搜索
python path
, 并将Python Path下路径修改成:
C:\Python37\python.exe
image.png
4.添加工作区文件夹
image.pngpip 问题?
若python安装程序没有成功安装pip,则可以手动安装pip。
若pip已经安装成功,则跳过此步骤。
详细步骤可参考 pip安装以及安装包时遇到的问题(作者:小碧小琳)
在本文不做过多展开
pip地址:https://pypi.org/project/pip/](https://pypi.org/project/pip/
还可以直接在VScode里面运行:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
大功告成:测试python环境是否可用
到此VScode for Python环境已经基本配置完成,打印hello world试试!
print("Hello, World!")
按下F5,调试配置选择python文件。
大功告成!