Windows/Linux 系统下 python 的安装与环境配置


1 Windows 系统下 python 安装
此次安装主要针对 windows 开发,因此是在 windows 10 系统下进行安装。
1.1 python 下载安装
Python 官网:Python Releases for Windows | Python.org

在这里找到自己需要的版本进行下载即可,但是建议大家不要下载最新版本,懂得都懂。。。下载完成后运行安装即可。
下载稳定版,具体下载版本需要看自己的电脑是多少位的,博主的电脑是 64 位的,因此安装的版本是 64 位的 3.7.4:
可进“设置→系统→关于”查看自己电脑的系统类型,博主的如下:

找到对应位数的版本

包含三种安装类型:
在线安装,即执行安装后才透过网络下载 python: Download Windows x86-64 web-based installer
exe 程序安装: Download Windows x86-64 executable installer
压缩文件解压缩安装: Download Windows x86-64 embeddable zip file
一般都选择 exe 程序安装
Download:windows x86 为 32 位,windows x86-64 为 64 位
如下是下载好的 exe 安装程序:

下载 exe 后,双击.exe 文件进入软件安装界面,选中【customize Installation】自定义安装, 并勾上【Add Python to PATH】添加环境变量(Python 3.7 添加到路径)选项,意思是把 Python 的安装路径添加到系统环境变量的 Path 变量中。


选择 Python 安装程序和安装位置,然后点击【Install】,软件会默认安装,或者想要更改安装程序的位置,点击【Browse】,在打开的窗口中自行选择软件安装位置,选择完成后点击【Install】。

之后就是等着进度条满,这个时间可能会比较长。

最后 Python 安装完成,点击【close】退出软件安装。
1.2 Python 环境变量配置
手动添加 python 环境变量过程
找到计算机,点击鼠标右键在弹出的选项中点击【属性】,然后点击【高级系统配置】

点击【环境变量】

在系统变量中,找到 Path,双击,在打开的编辑系统变量中,在末尾添加一个英文的分号,将 python 软件安装路径复制进去就可以了

搜索输入"cmd”或者 "win +R”输入 cmd 进入命令窗口 ,输入“python --version”并回车。如果出现 python 版本,则安装成功

可以在命令提示符中输入"Python"命令来启动 Python 解释器:执行以上命令后,出现如下窗口信息:

安装后 python 找不到的可能情况及解决办法:
1、先关闭 cmd,然后重新打开,再输入“python --version”并回车,如果可以了,那就说明 cmd 打开后安装的;
2、点击下载的安装包,选择 repair,根据提示重新来一次;
3、若没有出现 python 版本,应该是环境变量没有设置好,打开系统环境变量的 Path 变量,查看是否有 Python 的目录。若没有,那就手动配置环境变量。
1.3 VScode 使用 python

根据自己电脑系统选择对应的版本进行下载
VScode 启动后的界面如下图所示:

要在 VScode 中使用 python 就需要安装 python 插件,如下:
方法一:首先点击如下图样,然后在搜索框中输入:Python,如下图所示,点击下图中红框内的按钮安装插件,点击后红框内的按钮会变成“Installing”,等待,直到“Installing”消失。

方法二:在搜索框中输入
@id:ms-python.python

安装完 python 后需要选择 python 解释器,在 VScode 界面下,按键盘快捷键:F1
(或者Ctrl
+Shift
+P
),在 VScode 界面上方会显示下图中红色框内的文本框

在命令栏中输入Python:Select Interpreter
,并选择,如下图所示:

之后会出现对应的 python 解释器,如下所示(主要看自己电脑装的是什么版本的 python,以及装在什么路径):

VScode 终端安装库

pip list 查看安装的所有库:

2 Linux 系统下 python 安装
2.1 python 下载安装
Python 官网:Python Source Releases | Python.org

Linux/Unix 的系统上,一般默认的 python 版本为 2.x,可以将 python3.x 安装在 /usr/local/python3 目录中。
如果不想在官网下载,也可以通过以下方式进行下载,但需要注意的是修改自己需要的版本号:
解压 Python-3.7.4.tgz:tar -zxvf Python-3.7.4.tgz
建立一个空文件夹,用于存放 python3 程序:mkdir /usr/local/python3
执行配置文件,编译,编译安装
建立软连接
验证和测试
2.2 python 环境变量配置
安装完成后,可以将路径 /usr/local/python3/bin 添加到自己的 Linux/Unix 操作系统的环境变量中,这样就可以通过 shell 终端输入下面的命令来启动 Python3 。
2.3 安装 pip 相关依赖
安装 pip 相关依赖
下载并安装 setuptools
安装 pip3
验证查看 pip 安装版本
版权声明: 本文为 InfoQ 作者【左手の明天】的原创文章。
原文链接:【http://xie.infoq.cn/article/439a9955081d4ec0fad8c8565】。文章转载请联系作者。
评论