本来安装了miniconda,但是发现打开PowerShell后指令前没有(base),就卸载了,打算安装anaconda。
关于anaconda与python版本对应问题
安装anaconda后,其会在他的环境之下安装对应版本的python,所以不同担心。至于不使用conda环境时,cmd会运行哪个python,与环境变量中原先python和conda那个在前面有关系。
关于conda安装步骤
- 安装包下载
可以在官网上下载:官网
官网下载速度较慢,可以使用清华大学开源软件镜像站下载:镜像站
下载最新的就好。
- 下载好后点击exe安装
我的选择是:
Install for: All Users
Destination Folder:D:\Anaconda3
Advanced Options: Add Anaconda3 to system PATH(无法选则); Register Anaconda3 as the system Python 3.9(选择)
- 添加环境变量
打开cmd,验证conda版本:
C:\Users\ASUS>conda --version conda 22.9.0
验证是否有conda的python:
C:\Users\ASUS>where python D:\Anaconda3\python.exe C:\Users\ASUS\AppData\Local\Microsoft\WindowsApps\python.exe
查看conda具体信息:
C:\Users\ASUS>conda info active environment : None user config file : C:\Users\ASUS\.condarc populated config files : conda version : 22.9.0 conda-build version : 3.22.0 python version : 3.9.13.final.0 virtual packages : __cuda=12.0=0 __win=0=0 __archspec=1=x86_64 base environment : D:\Anaconda3 (read only) conda av data dir : D:\Anaconda3\etc\conda conda av metadata url : None channel URLs : https://repo.anaconda.com/pkgs/main/win-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/win-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/msys2/win-64 https://repo.anaconda.com/pkgs/msys2/noarch package cache : D:\Anaconda3\pkgs C:\Users\ASUS\.conda\pkgs C:\Users\ASUS\AppData\Local\conda\conda\pkgs envs directories : C:\Users\ASUS\.conda\envs D:\Anaconda3\envs C:\Users\ASUS\AppData\Local\conda\conda\envs platform : win-64 user-agent : conda/22.9.0 requests/2.28.1 CPython/3.9.13 Windows/10 Windows/10.0.19044 administrator : False netrc file : None offline mode : False
在cmd里输入以下命令设置清华镜像
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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
打开Anaconda Navigator (点击windows键,输入此名称并打开):
经过一大会儿的等待,出现这个界面,说明正常。这里有个对话框,询问是否更新,我选择了yes。然后又更新了不短时间。
conda的使用
因为我在学李沐的深度学习电子书,因此就按照那上面的教程使用了
激活PowerShell
PS E:\study\deapLearning\d2l-zh> conda init powershell ERROR during elevated execution. rc: [WinError 0] 操作成功完成。 no change D:\Anaconda3\Scripts\conda.exe no change D:\Anaconda3\Scripts\conda-env.exe no change D:\Anaconda3\Scripts\conda-script.py no change D:\Anaconda3\Scripts\conda-env-script.py no change D:\Anaconda3\condabin\conda.bat no change D:\Anaconda3\Library\bin\conda.bat no change D:\Anaconda3\condabin\_conda_activate.bat no change D:\Anaconda3\condabin\rename_tmp.bat no change D:\Anaconda3\condabin\conda_auto_activate.bat no change D:\Anaconda3\condabin\conda_hook.bat no change D:\Anaconda3\Scripts\activate.bat no change D:\Anaconda3\condabin\activate.bat no change D:\Anaconda3\condabin\deactivate.bat needs sudo D:\Anaconda3\Scripts\activate needs sudo D:\Anaconda3\Scripts\deactivate needs sudo D:\Anaconda3\etc\profile.d\conda.sh needs sudo D:\Anaconda3\etc\fish\conf.d\conda.fish no change D:\Anaconda3\shell\condabin\Conda.psm1 needs sudo D:\Anaconda3\shell\condabin\conda-hook.ps1 no change D:\Anaconda3\Lib\site-packages\xontrib\conda.xsh needs sudo D:\Anaconda3\etc\profile.d\conda.csh modified C:\Users\ASUS\Documents\WindowsPowerShell\profile.ps1 ==> For changes to take effect, close and re-open your current shell. <== Operation failed.
再次打开PowerShell,命令前出现base:
(base) PS E:\study\deapLearning\d2l-zh>
创建d2l环境:
(base) PS E:\study\deapLearning\d2l-zh> conda create --name d2l python=3.8 -y Collecting package metadata (current_repodata.json): /
一段时间后:
done # # To activate this environment, use # # $ conda activate d2l # # To deactivate an active environment, use # # $ conda deactivate Retrieving notices: ...working... done
安装pytorch和d2l包
pip install torch
pip install torchvision
pip install d2l
我先前就已经下载了D2L Notebook,因此直接在目录下jupyter notebook运行。大功告成!
本文参考了以下文章,在此表示感谢:
Anaconda安装与Python环境搭建(不看后悔版)
python与anaconda区别及先后安装的问题