Daibingh Less is more, slow is fast.

python 版本和包的管理

2018-09-21
hdb

conda

conda 创建python环境

conda create -n env_name python=2.7

conda 查看环境

conda info -e

conda 切换环境

conda activate env_name # windows
source activate env_name # linux

conda 删除环境

conda remove -n env_name --all

修改 conda 源

# 中科大
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
# 清华
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda config --remove-key channels  # 还原 conda 源

安装/卸载/查看/升级包

conda list # 查看包
conda install xxx # 安装包
conda remove xxx # 卸载包
conda update xxx  # 升级包

pip

强制重新安装

pip install --force-reinstall numpy==1.16.0

修改 pip 源

清华:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

可以在使用pip的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例如:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx

这样就会从清华这边的镜像去安装 xxx 库。

永久修改

linux: 修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

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

windows: C:\Users\hdb\AppData\Roaming\pip,新建文件 pip.ini,内容如下

[global]
timeout = 6000
index-url = https://pypi.douban.com/simple

安装/卸载/查看/升级包

pip list # 查看包
pip install xxx # 安装包
pip remove xxx # 卸载包

参考


Comments

Content