Python环境管理:Anaconda使用

Python环境管理:Anaconda使用

 

1、anaconda安装后需要更换国内源,以加快下载速度

1.1  命令行中更改

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

1.2  在配置文件中更改

在C:\Users\用户名\.condarc中进行更改,例如以下部分示例:

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/mro/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/pro/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/r/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - 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/mro/
  - defaults
show_channel_urls: true
ssl_verify: True

在此注明一下,上述更改的是conda命令的配置,如果需要更改pip命令的源地址,可用的方法是:

在文件夹C:\Users\用户名\pip中添加pip.ini文件,文件内容编辑如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

2、在Anaconda使用conda命令配置各种虚拟环境

例如,创建一个python27的环境,python版本为python2.7,可用如下方法:

conda create -n python27 python=2.7

这样就很轻松地创建了一个python2.7环境,类似还可以创建很多不同配置的环境以满足自己的需求。当要删除该环境时,执行如下命令:

conda remove -n python27 --all

切换环境用以下命令:

activate python27

# 退出使用
deactivate
发布了12 篇原创文章 · 获赞 3 · 访问量 9134

猜你喜欢

转载自blog.csdn.net/qq_22826709/article/details/80627860