将anaconda安装到D盘
-
创建开始菜单快捷方式,默认版本是3.11
-
Add Anaconda3 to the system PATH environment variable
,如果有复选框是加入path环境变量的,不要勾选,选上之后出现“无法定位到动态链接库”问题 -
手动添加path环境变量,并指向终端
-
修改虚拟环境的位置
# 查看虚拟环境默认位置
C:\Users\dogle>conda env list
# conda environments:
#
D:\software\Anaconda3
base D:\software\anaconda3
# 修改如下文件,去掉多余的目录
C:\Users\dogle\.conda\environments.txt
# 创建虚拟环境
C:\Users\dogle>conda create -n env_dev python=3.7
# 查看虚拟环境默认位置,C:\Users\dogle\.conda\envs\env_dev中envs为110MB,paks为300MB
C:\Users\dogle>conda env list
# conda environments:
#
env_dev C:\Users\dogle\.conda\envs\env_dev
base D:\software\anaconda3
# 使用编辑器打开如下文件
C:\Users\dogle\.condarc
# 在D盘中新建文件夹,并追加如下,按顺序作为虚拟环境的存储路径
envs_dirs:
- D:\.conda\envs
- C:\Users\dogle\.conda\envs
- D:\software\anaconda3\envs
- C:\Users\dogle\AppData\Local\conda\conda\envs
pkgs_dirs:
- D:\.conda\pkgs
- C:\Users\dogle\.conda\pkgs
- D:\software\anaconda3\pkgs
- C:\Users\dogle\AppData\Local\conda\conda\pkgs
# 查看详细信息
C:\Users\dogle>conda info
active environment : None
user config file : C:\Users\dogle\.condarc
populated config files : C:\Users\dogle\.condarc
conda version : 23.7.4
conda-build version : 3.26.1
python version : 3.11.5.final.0
virtual packages : __archspec=1=x86_64
__win=0=0
base environment : D:\software\anaconda3 (read only)
conda av data dir : D:\software\anaconda3\etc\conda
conda av metadata url : None
channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
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:\.conda\pkgs
C:\Users\dogle\.conda\pkgs
D:\software\anaconda3\pkgs
C:\Users\dogle\AppData\Local\conda\conda\pkgs
envs directories : D:\.conda\envs
C:\Users\dogle\.conda\envs
D:\software\anaconda3\envs
C:\Users\dogle\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/23.7.4 requests/2.31.0 CPython/3.11.5 Windows/10 Windows/10.0.22631 aau/0.4.2 c/43RviIKyg6z3vcHeSFLGYw s/xXQS7ibQkrfmyyosMKUI1g e/Viw0aQqI5GPuHGSVbC_3aA
administrator : False
netrc file : None
offline mode : False
# 创建虚拟环境
C:\Users\dogle>conda create -n env_dev1 python=3.7
# 查看虚拟环境默认位置,D:\.conda\envs\env_dev1中envs为110MB,paks为150MB
C:\Users\dogle>conda env list
# conda environments:
#
env_dev C:\Users\dogle\.conda\envs\env_dev
env_dev1 D:\.conda\envs\env_dev1
base D:\software\anaconda3
# 删除C:\Users\dogle\.conda\envs\env_dev虚拟环境,此时envs为0MB,paks为300MB
conda remove -n env_dev --all
# 执行如下命令删除paks,这时C:\Users\dogle\.conda\pkgs和D:\.conda\pkgs都会清空
C:\Users\dogle>conda clean -a
Will remove 11 (29.0 MB) tarball(s).
Proceed ([y]/n)? y
Will remove 2 index cache(s).
Proceed ([y]/n)? y
Will remove 11 (110.8 MB) package(s).
Proceed ([y]/n)? y
There are no tempfile(s) to remove.
There are no logfile(s) to remove.
# 之后每次创建新的虚拟环境都只会占用D:\.conda的envspkgs
conda create -n env_dev2 python=3.7
- 占用文件夹
D:\software\anaconda3 安装目录
D:\software\anaconda3\envs
D:\software\anaconda3\pkgs
D:\.conda
D:\.conda\envs
D:\.conda\pkgs
C:\Users\dogle\.conda
C:\Users\dogle\.conda\envs
C:\Users\dogle\.conda\pkgs
C:\Users\dogle\AppData\Local\conda\conda
C:\Users\dogle\AppData\Local\conda\conda\envs
C:\Users\dogle\AppData\Local\conda\conda\pkgs
# 其他
C:\Users\dogle\.anaconda
C:\Users\dogle\.condarc
C:\Users\dogle\.conda\environments.txt
- 虚拟环境中site-packages替换
# 先安装Anaconda3-2023.09,创建虚拟环境env_dev1指定版本python3.7,在该虚拟环境中安装依赖并且成功运行代码
# 将D:\.conda\envs\env_dev1\Lib\site-packages压缩并移动到其他位置,卸载Anaconda3-2023.09
# 再安装Anaconda3-2019.07,默认的base环境为python3.7.3
# 直接将2019.07的D:\software\anaconda3\Lib\site-packages替换为2023.09的env_dev1的site-packages也可以运行代码