conda与pip命令行工具使用与配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# 查看所有python环境
conda info -e
# 查看当前python版本号
python -V
# 创建一个新的python环境
conda create --name python27 python=2.7
# 安装R 语言环境
conda install R
# 安装rstduio
conda install rstudio
# 激活切换python环境
activate python27
# 回到上个环境
deactivate
# 删除已有环境
conda remove --name python27 --all
|
1
2
3
4
5
6
7
8
9
|
# 查看环境包列表
conda list
# 查找beautifulsoup4的包
conda search beautifulsoup4
# 为python34安装beautifulsoup
# Tips:
# 你必须告诉conda你要安装包的环境的名称,不然会安装在当前环境下。
# 这里的环境就是python34
conda install --name python34 beautifulsoup4
|
添加镜像
1
2
3
4
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
conda config --set show_channel_urls yes
|
conda 镜像配置
编辑配置 ~/.condarc
或查看配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
channels:
- defaults
show_channel_urls: true
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
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
|
pip 镜像配置
编辑配置 ~/.pip/pip.conf
或查看配置文件
1
2
|
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
|
pip使用命令时添加-i
参数指定镜像源
1
2
3
|
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scrapy -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
|
conda 与pip使用注意事项
使用conda创建隔离环境下,使用pip下载包,默认会下载到对应的环境下,然而使用pip3下载包会下载到默认conda环境下
实际情况:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# 在默认conda环境下,查看pip和pip3路径详情
$ pip -V
pip 20.0.2 from /usr/local/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
$ pip3 -V
pip 20.0.2 from /usr/local/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
# 可以看出site-package 为同一个而且路径放在conda默认环境下
# 切换一个自己创建的环境,比如我的paddle环境
$ pip -V
pip 20.0.2 from /usr/local/anaconda3/envs/paddle/lib/python3.7/site-packages/pip (python 3.7)
$ pip3 -V
pip 20.1.1 from /Users/iki/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)
# 可以看出site-package指向的是默认的环境包位置,因为在这个paddle环境下并没有安装pip3
# 查看paddle环境下安装的可执行程序
$ ll /usr/local/anaconda3/envs/paddle/bin
# 可以看到没有安装pip3
# 总结 conda 使用python3.x环境,pip和pip3默认都是pip 20.0.2了,在自己的环境下使用pip安装就可了,不需要使用pip3.
|