1、Anaconda下载和安装
做深度学习时,不建议直接使用官方python,而是用Anaconda。
Anaconda 是推荐的 python开发包集合,在官网下载所需的版本。安装好后就已经集成了Python IDE:jupyter notebook和spyder等常用库。
Anaconda下载地址:Anaconda Installers and Packages
但是外网速度慢,推荐清华大学的镜像站:Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
参考Anaconda 镜像使用帮助完成下载安装及conda镜像源的设置:anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
这里做Anaconda官网下载的操作演示:
首先进入官网:Anaconda Installers and Packages,选择View All Installers
以Aanaconda3为例(anaconda3就代表Python3的版本),后面是发行日期,以2024.02的Windows版本,64位为例。
运行安装程序,按照步骤,依次选择next->I Agree->All Users
在C盘空间足够(建议C盘剩余空间有300G以上可以考虑安装到C盘)的情况下安装到C盘默认路径下。(这样能确保安装在系统盘内,系统盘一般是固态硬盘,读写速度较快)
接着按照默认选项(或者选择Clear the package cache upon completion----安装完成后清理安装包)进行安装即可。
安装完成后,可以运行程序,并安装自己所需要的anaconda配置,推荐安装如下:
接着,在win11下栏搜索anaconda,运行anaconda prompt即可进入anaconda初始的base环境
2、配置镜像
通过编辑.condarc文件并设置清华大学镜像源,可以加速conda包的下载和更新。
首先打开anaconda prompt,并执行conda config生成.condarc文件
conda config
.condarc文件一般在C:\Users\[***name***]\.condarc路径下的,可以借助之前文章推荐的everything软件(便捷小工具汇总-CSDN博客)检索.condarc文件。
使用记事本打开.condarc文件并将以下内容替换原内容,修改后保存并退出即可。
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
3、配置环境变量
设置环境变量的目的是确保你可以在命令行CMD或powershell直接使用Python和Conda命令,不需要每次都切换到Anaconda的安装目录。
在win11下栏输入sysdm.cpl并运行,点击高级-环境变量:
在系统变量里找到Path,并进入编辑:
在安装anaconda的路径下,找到以下三个文件并新建至系统变量Path中,以下为本人文件为例:
C:\ProgramData\anaconda3
C:\ProgramData\anaconda3\Scripts
C:\ProgramData\anaconda3\Library\bin
完成环境变量配置后,WIN+R并输入CMD打开命令提示符,在命令提示符里面分别输入
conda --version
查看Anaconda版本
python
查看python版本
若均出现版本号,则代表环境变量配置成功(若报错请重启cmd再次尝试)。
之后就可以在CMD和powershell直接使用Python和Conda命令啦,当然也可以通过Anaconda自带的anaconda prompt直接运行以上介绍的conda指令来查看Anaconda版本和Python版本,这里的Anaconda版本和Python版本都是base环境中的版本。
CMD中:
powershell中:
PS:有些小伙伴的powershell可能出现无法加载文件 “C:\Users\Trafalgar\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本”的问题。
这时,打开powershell并输入指令get-ExecutionPolicy,若输出返回Restricted,则说明脚本执行策略受限。
get-ExecutionPolicy
这时我们只需要重新以管理员身份运行powershell,更换脚本执行策略即可:
set-ExecutionPolicy RemoteSigned
,然后输入 Y
set-ExecutionPolicy RemoteSigned
此时我们输入get-ExecutionPolicy 查看脚本执行策略,输出返回RemoteSigned说明脚本执行策略已经成功更改啦!如下可以正常使用了:
未完待续~