前言
每次搭建Python环境都会忘记安装Python和VSCode的要点和配置方法,为了方便自己,专门把这些配置方法和设置心得整理记录下来,也可以供其他人参考。
备注:这个说明适用于Windows 11环境,Linux和MacOS以后有条件再写。
题外话,个人感觉Anaconda有些臃肿,有些要用的包它没有,它安装的很多包自己又用不上。所以,还是喜欢按自己的想法全部定制化安装,可以做到精准控制,相对安装好的软件所占用的空间也并不太大。
1 Python安装
1.1 下载Python
选择自己需要的版本和对应操作系统Win、Linux、MacOS版本。
这篇文章说的是Windows环境,所以可以从以下地址下载Windows版本的:Python Releases for Windows | Python.orgThe official home of the Python Programming Languagehttps://www.python.org/downloads/windows/
Python版本推荐:3.11.xx版,本文编写的时候用的3.10.11,现在AI主流和兼容性较好的版本是3.11.xx版,根据个人的需求进行版本选择。
1.2 安装Python
Python下载完毕后,双击程序进行安装,默认安装,或者选择自定义安装,选择一个自己好找的目录进行安装,例如安装到:C:\Python 目录下,方便使用和管理。
注意:安装的时候勾上添加python到系统路径选项,否则还要手工设置Windows的环境变量。
1.3 配置pip和软件包
打开Windows的cmd命令行窗口(按Win+R,输入:cmd回车):
首先升级pip版本:
# 升级pip到最新版本
python.exe -m pip install --upgrade pip
# 查看pip版本
pip list
为了提高pip下载软件包的速度,设置pip的默认下载源为国内源,这里设置的是清华源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
还有其它国内源,根据自己的需要配置:
阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
豆瓣源
pip config set global.index-url https://pypi.douban.com/simple/
1.4 配置Jupyter Notebook
安装Jupyter Notebook:
pip install notebook
配置Jupyter Notebook默认工作目录:
方法一:使用命令行参数
jupyter notebook --notebook-dir=D:\jupyter
方法二:创建配置文件并修改配置文件
jupyter notebook --generate-config
Writing default config to: C:\Users\username\.jupyter\jupyter_notebook_config.py
注:username是自己登录Windows的账号名称。
编辑配置文件(C:\Users\username\.jupyter\jupyter_notebook_config.py):
搜索“notebook_dir”,找到代码行:# c.ServerApp.notebook_dir = ''。
删除注释#号,并配置默认目录:
c.ServerApp.notebook_dir = 'D:\jupyter'
保存退出。
运行测试Jupyter Notebook:
打开cmd窗口,运行:
jupyter notebook
会自动打开Jupyter浏