- anoconda 使用过程中基本问题概览
- anaconda 使用相关
- 查看版本:
- 查看已有的虚拟环境:
- 升级检查版本:
- 导出/导入环境
- 切换(激活)环境:
- 退出环境:
- 删除虚拟环境:(不要乱删,特别是base)
- 下载速度慢
- 清华源地址
- 通过代理下载
- `pip` 可安装的包通过 `conda` 却不一样
- 安装时指定仓库
- 永久配置额外仓库
- jupyter
- `conda` 安装 `pip` 包
anaconda 使用相关 查看版本:写在前面: 根据以往经验一个字一个字的认真写的, 所以不妨点个赞然后再拿走…
conda --version查看已有的虚拟环境:
conda info --envs升级检查版本:
conda update conda导出/导入环境
# 导出 conda env export > freeze.yml # 导入 conda env create -f freeze.yml切换(激活)环境:
Windows: activate py36 Linux and macOS: source activate py36退出环境:
Windows: deactivate Linux, macOS: source deactivate删除虚拟环境:(不要乱删,特别是base)
conda remove -n py36 --all下载速度慢
解决下载速度慢有两种方法, 一种是更改下载地址, 另一种是使用代理.
清华源地址anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
通过代理下载如果你有代理软件的话, 建议用代理软件下载. 原因有:
- 清华源有时候会出现方法访问的问题, 或者访问特别慢的问题;
- 你有时候从 conda 官网下包, 有时候从镜像站点下载, 混合着用也可能会出现问题;
一种可能是codna仓库内没有收入相关包, 不过更大的可能是你需要配置额外的仓库 或者 安装的时候指定额外的仓库.
需要查看到底有没有被 conda 仓库收入, 可以通过:
- 网上搜索
- 官方仓库查找: https://anaconda.org/search
conda install -c conda-forge xxx永久配置额外仓库
查看已经配置的下载仓库的指令如下:
# 方式一: conda config --show-sources # 方式二: conda config --get channels
同上, 我想要添加 conda-forge 仓库, 那么可以通过以下方式更改:
- 指令添加: conda config --append channels conda-forge
- 更改配置文件:
- win: C:Users{这是你电脑的用户名}.condarc
- Linux: ~/.condarc
更改后的效果如下:
channels: - defaults - conda-forgejupyter
安装了多个环境, 在jupyter 中却不能随意的切换环境.
conda install nb_conda_kernels # 应该是可选的吧. conda install ipykernel jupyter notebook conda install ipykernel # 切换到相应的环境, 然后将环境写入notebook的kernel中 python -m ipykernel install --user --name 环境名称 --display-name "Python (环境名称)" # 会生成相应的文件: ## WIN. C:UsersxxxAppDataRoamingjupyterkernels ## Ubuntu.
并重新启动notebook,在kernel -> change kernel中即可切换到指定的虚拟环境
conda 安装 pip 包- 最简单的方式, 但是如果遇到找不到的包就会报错并停止安装后续的包.
conda install --yes --file requirements.txt
- 不停止, 并且安装所有能安装的包. 对于不能安装的包保存到 error.log.
# Ubuntu while read requirement; do conda install --yes $requirement; done < requirements.txt 2>error.log # Window ## 手动执行 for /f %i in (requirements.txt) do conda install --yes %i ## 在 BAT脚本 中 for /f %%i in (requirements.txt) do conda install --yes %%i
- 不停止, 如果 conda 不能安装, 那就通过 pip 安装
# Ubuntu while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt # Window FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f" ## Window
- 不停止, 如果还存在注释, 安装过程需要忽略
# Ubuntu while read req; do if [[ $req != "#"* ]]; then conda install --yes $requirement || pip install $requirement; fi; done < requirements.txt
我修改了一下代码, 方面看出安装了哪些包, 可选择性拿取:
while read requirement
do
echo ${requirement}
conda install --yes $requirement;
done < requirements.txt 1>conda_succ.log 2>conda_error.log
reference:
@online{BibEntry2021Nov,
title = {{Install only available packages using “conda install --yes --file requirements.txt” without error}},
organization = {Stack Overflow},
year = {2021},
month = {11},
date = {2021-11-04},
urldate = {2021-11-04},
note = {[Online; accessed 4. Nov. 2021]},
url = {https://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t},
abstract = {{While installing packages in requirements.txt using Conda through the following command conda install --yes --file requirements.txt If a package in requirements.txt is not available, then it throw…}}
}
@online{BibEntry2021Nov,
title = {{Install Python dependency packages from requirements.txt using conda.}},
organization = {Gist},
year = {2021},
month = {11},
date = {2021-11-04},
urldate = {2021-11-04},
language = {english},
hyphenation = {english},
note = {[Online; accessed 4. Nov. 2021]},
url = {https://gist.github.com/luiscape/19d2d73a8c7b59411a2fb73a697f5ed4},
abstract = {{Install Python dependency packages from requirements.txt using conda. - install_packages.sh}}
}



