Anaconda 基本操作指令
conda 创建新环境
如果只是用的话,用【创建】和【激活】的命令足够了~
第一步:创建
conda create --name yourEnv python=2.7
- –name:也可以缩写为 【-n】,【yourEnv】是新创建的虚拟环境的名字,创建完,可以装 anaconda 的目录下找到 envs/yourEnv 目录
- python=2.7:是 python 的版本号。也可以指定为【python=3.6】,若未指定,默认为是装 anaconda 时 python 的版本.
若想要在创建环境同时安装 python 的一些包:
conda create -n yourEnv python=3.6 numpy pandas
若想在别人虚拟环境的基础上创建自己的环境:
conda create --name <yourEnv> --clone <baseEnv>
第二步:激活
windows ==> activate yourEnv
linux/mac ==> source activate yourEnv
tips:
-
linux 用户需要进入到 anaconda/envs 目录下激活需要的环境,或者通过命令
source active /home/yourName/anaconda3/envs/yourEnv
激活需要的环境;上面激活的方式进入目录太复杂 or 命令太长了,可以通过设置全局变量或者用 linux 的别名 alias 设置。
- 第一种方式,将需要激活的路径下的 bin 文件添加到全局环境变量中如将 /home/yourName/anaconda3/envs/yourEnv/bin 添加到 ~/.bash_profile 中。
- 第二种方式,通过 vim ~/.bash_profile,向里面添加 alias activeEnv='source activate /home/yourName/anaconda3/envs/yourEnv',source ~/.bash_profile 之后可以直接在命令行输入 activeEnv 激活相应
建议第二种,并建议看下 linux 的 alias,非常好用
-
windows 用户环境变量中添加(改成自己的路径):
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
第三步:查看活跃的环境
conda info --envs:输出中带有【】号的的就是当前所处的环境
conda一些命令
conda list:看这个环境下安装的包和版本
conda install numpy scikit-learn:安装 numpy sklearn 包
conda env remove -n yourEnv:删除你的环境
conda env list:查看所有的环境
anaconda下载
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
bash Anaconda3-5.3.1-Linux-x86_64.sh
清华镜像源配置
清华官方说明:Anaconda 镜像使用帮助,主要概括为向 .condarc 填充以下内容:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
-
Linux:直接 vim ~/.condarc 后添加;
-
Windows:无法直接创建名为 .condarc 的文件,可先执行
conda config --set show_channel_urls yes
生成该文件之后再添加。
conda config --add channels http://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes
其他注意:
pytorch 安装不成功
-
记得加上清华 pytorch 镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ # for legacy win-64 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
-
官网可以根据自己的系统等直接生成安装的命令,如果镜像后还是不成功将官方的安装命令
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
去掉 -c pytorch,改为
conda install pytorch torchvision cudatoolkit=10.0
-
cuda 版本查看
cat /usr/local/cuda/version.txt
keras 和 tersorflow 对应版本问题
-
两个版本如果不匹配可能出现:module ‘tensorflow.python.keras.backend’ has no attribute ‘get_graph’。可以从
这里查看对应的版本
pip uninstall keras # 卸载keras conda install keras=2.2.4 #安装对应版本的keras
torchnet 安装
- 手动:https://blog.csdn.net/weixin_43264516/article/details/83187775
- 官方:pip install torchnet
- git: pip install git https://github.com/pytorch/tnt.git@master
评论区