windows下 conda常用使用指令

278 阅读3分钟

conda的常用命令操作

# 创建一个名为python34的环境,指定Python版本是3.4(不用管是3.4.x,conda会为我们自动寻找3.4.x中的最新版本)
conda create --name python34 python=3.4

# 安装好后,使用activate激活某个环境
activate python34 # for Windows
source activate python34 # for Linux & Mac
# 激活后,会发现terminal输入的地方多了python34的字样,实际上,此时系统做的事情就是把默认2.7环境从PATH中去除,再把3.4对应的命令加入PATH

# 此时,再次输入
python --version
# 可以得到`Python 3.4.5 :: Anaconda 4.1.1 (64-bit)`,即系统已经切换到了3.4的环境

# 如果想返回默认的python 2.7环境,运行
deactivate python34 # for Windows
source deactivate python34 # for Linux & Mac

# 删除一个已有的环境
conda remove --name python34 --all


--------------------- -------------------------------------------------------
使用conda管理包

# 安装scipy
conda install scipy
# conda会从从远程搜索scipy的相关信息和依赖项目,对于python 3.4,conda会同时安装numpy和mkl(运算加速的库)

# 查看已经安装的packages
conda list
# 最新版的conda是从site-packages文件夹中搜索已经安装的包,不依赖于pip,因此可以显示出通过各种方式安装的包

# 查看当前环境下已安装的包
conda list

# 查看某个指定环境的已安装包
conda list -n python34

# 查找package信息
conda search numpy

# 安装package
conda install -n python34 numpy
# 如果不用-n指定环境名称,则被安装在当前活跃环境
# 也可以通过-c指定通过某个channel安装

# 更新package
conda update -n python34 numpy

# 删除package
conda remove -n python34 numpy

# 更新conda,保持conda最新
conda update conda

# 更新anaconda
conda update anaconda

# 更新python
conda update python
# 假设当前环境是python 3.4, conda会将python升级为3.4.x系列的当前最新版本

注意:在以上的使用过程中你会发现使用conda下载包的速度非常的慢,因为使用的是国外的服务器,所以这里要设置为国内的镜像。使用下面的配置命令即可:

windows下
在清华源和中科大源之间自行选择

1 添加清华源
命令行中直接使用以下命令

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/msys2/

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes


2 添加中科大源

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

conda config --set show_channel_urls yes



Linux下
将以上配置文件写在~/.condarc中 

vim ~/.condarc

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true


--------------------- 

个人觉得还是临时指定安装源吧,当你确实下载很慢的时候。

# 添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# TUNA的help中镜像地址加有引号,需要去掉

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes


----------------------------------------------------------------------------------------------

pycharm中使用anaconda 这里讲下在pycharm上anaconda的配置:

在Pycharm的Files>>settings>>Project Interpreter>>Add local 里面添加Anaconda python.exe. 应用之后就可以调用各种Anaconda的库啦,如果下载了其他版本的python,将envs中的python.exe也添加到Project Interpreter 中,在需要的时候进行切换就可以了
如下面的图片所示:

参考:

conda添加清华镜像源

pip conda 换清华源