mac下vscode配置python开发环境

您所在的位置:网站首页 苹果电脑如何安装python mac下vscode配置python开发环境

mac下vscode配置python开发环境

2023-09-28 21:02| 来源: 网络整理| 查看: 265

mac下vscode配置python开发环境

首先先给大家推荐vscode官网上面的配置指引链接:https://code.visualstudio.com/docs/python/python-tutorial ,上面的配置内容比较详细,同样我也会给出自己的配置过程。

整个配置过程分为以下三步:

下载vscode下载python修改vscode配置

下载vscode比较简单,本文将不再详述,配置过程从下载python说起。

1、下载python

mac电脑自带python2.7,如果觉得满足自己需求,可跳过这一步。python的下载方法有两种:(1)通过官网下载最新稳定版本,python官网,安装完之后会自动在/usr/local/bin/目录下创建python3的软链接,能够直接在终端里面输入python3进入python命令行。如下:

SchillerdeMBP:~ schillerxu$ cd /usr/local/bin SchillerdeMBP:bin schillerxu$ ls 2to3 pip3 python3.7 2to3-3.7 pip3.7 python3.7-config brew pydoc3 python3.7m easy_install-3.7 pydoc3.7 python3.7m-config idle3 python3 pyvenv idle3.7 python3-config pyvenv-3.7 SchillerdeMBP:bin schillerxu$ ls -al |grep python lrwxr-xr-x 1 root wheel 69 9 1 19:29 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.7/bin/python3 SchillerdeMBP:bin schillerxu$ python3 Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>

(2)第二种是通过homebrew下载,homebrew类似于centos的yum,可简单的理解为mac平台下的一个软件管理工具,配置和使用可参考:homebrew是个啥

2、vscode安装python插件并修改配置

Python插件安装之后需要确定使用的解释器,可以通过打开命令选项板(⇧⌘P)然后输入“python:选择解释器”选择Python版本。编译器配置之后会将参数python.pythonpath修改为解释器的路径,参数查看的路径:code > 首选项 > 设置 > 工作区,然后在上面的搜索栏输入pythonpath就能找到参数。 也可以通过直接修改python.pythonpath参数指定需要使用的python版本。

3、创建示例代码并运行

新建文件,然后保存为test.py,文件以py作为后缀名,是告诉vscode这是个python程序,然后就能使用Python插件。 示例代码:

msg="helloworld" print(msg)

运行代码 1、可以“右键”选择“在终端中运行python文件”或者是“Run Code”(需要安装code runner插件) 2019-09-05-16-44-27 2、或者是在终端用命令行运行代码

#得在test.py文件目录下运行命令 $ cat test.py msg="helloworld" print(msg) $ python test.py helloworld


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3