使用Miniconda创建多个python虚拟环境
前言
Conda 基于 Python 开发,是一个开源、跨平台、语言无关的包管理与环境管理系统。支持 Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN 等语言。
安装 Conda 比较繁琐,耗时且占用空间很大。Miniconda 比 conda 小,安装更快。使用 miniconda 可创建多个互不影响的 python 虚拟运行环境,且自带 pip。
根据操作系统到 miniconda 官网下载安装脚本,推荐到清华镜像站下载。
macos(intel cpu) 安装
下载 Miniconda3-latest-MacOSX-x86_64.pkg安装即可。
或者使用命令安装(不推荐):
curl -LO https://mirrors.bfsu.edu.cn/anaconda/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sudo /bin/bash ./Miniconda3-latest-MacOSX-x86_64.sh -u
Centos 安装步骤
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3*.sh
# -p PREFIX: defaults to /root/miniconda3
./Miniconda3*.sh -b -p /opt/conda
# export PATH="/root/miniconda3/bin:$PATH"
创建公用的环境变量vi /etc/profile.d/conda.sh
export PATH="/opt/conda/bin:$PATH"
重新打开一个终端,测试是否安装成功which conda
使用 conda 的镜像加速
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 --set show_channel_urls yes
如果不想用镜像,可取消
conda config --show channels
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
创建虚拟环境
conda create -n py3 python=3
conda env list
source activate py3
更多命令请参考官方文档
配置pip镜
mkdir ~/.pip && vim ~/.pip/pip.conf
,内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
参考