pip 与 conda

pip 与 conda

pip 修改镜像源

首先我们需要打开个人用户路径:

然后新建一个 pip 文件夹,进入文件夹下新建一个 pip.ini 的文件,在文件中添加如下内容:

# 使用清华镜像源添加以下内容:
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
# 使用豆瓣镜像源添加以下内容:
[global]
index-url=https://pypi.douban.com/simple/
[install]
trusted-host=pypi.douban.com
# 使用阿里镜像源添加以下内容:
[global]
index-url=https://mirrors.aliyun.com/simple/
[install]
trusted-host=mirrors.aliyun.com

注意:Linux 配置 pip 镜像稍有不同,在更目录下创建或修改 ~/.pip/pip.conf pip 配置文件,其内容相同

conda 修改镜像源

这里我们同样使用清华大学镜像源

windows 下在用户文件夹下创建文件 .condarc(一般在安装好 anaconda 就会有这个文件,不需要手动创建),注意该文件是隐藏文件,进入该文件写入以下内容:

show_channel_urls: true
default_channels:
  - 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/cloud/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
channel_priority: flexible

安装与卸载 pkg 包

这里 conda 与 pip 安装和写在 pkg 包的方法相同,示例如下:

# 安装默认版本
pip install 包名
conda install 包名
# 安装指定版本
pip install 包名+版本号
conda install 包名+版本号
# 卸载包,这里不需要加版本号
pip uninstall 包名
conda uninstall 包名

这里直供电介绍一下如何在虚拟环境下安装包:

首先我们需要打开一个虚拟环境,然后运行 conda 的包安装命令:

conda install -n 指定虚拟环境名 包名

如果这里不加 -n 指定虚拟环境名 则会将包默认安装在当前环境下

posted @ 2023-03-02 22:05  ppqppl  阅读(14)  评论(0编辑  收藏  举报