执行要求:已成功安装Anaconda,打开Anaconda prompt
安装pytorch时候,从pytorch官网复制下载代码,记得删掉后面的-c pytorch,因为它表示从官网进行下载,不从清华镜像源下。
1. 创建环境
- conda create -n 环境名 python=版本号
- #例如:conda create -n newenvi python=3.7
2. 激活环境
- conda activate 环境名
- #例如:conda activate myproject
3. 退出环境
-
- conda deactivate
4. 查看 & 删除 已创建的环境
- # 4.1 查看已创建环境
- conda info --env
- #或者
- conda env list
- # 4.2 删除不需要的环境
- conda remove -n 环境名 --all
- # 4.3 查看环境是否删除成功
- conda info --env
5. 配置Anaconda为国内镜像源
- 5.1 显示镜像源
- conda config --show channels
- """
- 注意:anaconda 默认是国外镜像源,默认显示以下内容:
- channels:
- -defaults
- """
-
-
- 5.2 重置镜像源
- conda config --remove-key channels #删除所有的镜像源,恢复到默认
- or
- conda config --remove channels [urls] #删除指定的镜像源
-
- 5.3 执行下面两条命令,配置国内镜像源
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
-
- conda config --set show_channel_urls yes
-
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
-
-
- 5.4 查看是否配置成功
- conda config --show channels
- """
- 若显示以下内容则配置成功
- channels:
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- - defaults
- """
-
- 5.5 常用的Anaconda镜像
- http://mirrors.aliyun.com/pypi/simple/ #阿里
- https://pypi.tuna.tsinghua.edu.cn/simple/ #清华
- http://pypi.douban.com/ #豆瓣
- http://pypi.mirrors.ustc.edu.cn/ #中国科学技术大学
6. 安装 & 卸载包
- 6.1 安装 & 卸载单个包
- conda install 包名
- conda uninstall 包名
-
- 6.2 安装 & 卸载指定版本的包
- conda install 包名==版本号
- conda uninstall 包名==版本号
-
- 6.3 批量安装卸载包
- (1) 切换到 requirements.txt 文件所在目录
- cd 目录
- (2) 执行下面命令,将requirements.txt内指定的包安装&卸载
- conda install -t requirements.txt
- conda uninstall -t requirements.txt
- 示例 requirements.txt 文件内容
- ...
- matplotlib>=2.2
- numpy>=1.15.0, <1.21.0
- pandas
- pytest==4.0.1
- ...
文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树预备知识安装Python417831 人正在系统学习中
评论记录:
回复评论: