ToB企服应用市场:ToB评测及商务社交产业平台
标题:
Linux 下安装 miniconda,管理 Python 多环境
[打印本页]
作者:
小小小幸运
时间:
2023-11-7 20:05
标题:
Linux 下安装 miniconda,管理 Python 多环境
安装 miniconda
1、下载安装包
Miniconda3-py37_22.11.1-1-Linux-x86_64.sh
,或者
自行选择版本
2、把安装包上传到服务器上,这里放在 /home/software
3、安装
bash Miniconda3-py37_22.11.1-1-Linux-x86_64.sh
复制代码
4、按回车
Welcome to Miniconda3 py37_22.11.1-1
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
复制代码
5、按空格跳到最下面,输入yes
Do you accept the license terms? [yes|no]
[no] >>> yes
复制代码
6、选择安装位置,这里选择默认,直接回车,有需要可以自己输入改掉
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/miniconda3] >>>
PREFIX=/root/miniconda3
复制代码
7、初始化 miniconda,输入 yes
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
复制代码
8、现在 conda 命令是找不到的,需要激活
source ~/.bashrc
复制代码
激活后可以看到启动了 base 环境,conda 命令也可以用了,下一节会介绍常用 conda 命令。
9、可以设置启动时,不自动激活 base 环境
conda config --set auto_activate_base false
复制代码
10、设置 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
复制代码
11、设置 pip 镜像
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com
复制代码
12、查看 python 环境
(base) [root@xxx01 software]# python
Python 3.7.15 (default, Nov 24 2022, 21:12:53)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello')
hello
>>> exit()
复制代码
可以看到默认的 python 环境是 3.7,也就是我们安装的 miniconda 的 python 版本。
并且 python2 还是存在的。
(base) [root@xxx01 software]# python2
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello')
hello
复制代码
使用 miniconda 管理 python 多环境
这里简单介绍一些常用的 conda 命令。
1、查看所有环境
conda env list
复制代码
2、激活某个环境, 为环境名
conda activate <name>
复制代码
3、退出当前环境
conda deactivate
复制代码
4、创建虚拟环境,指定名字和 python 版本
conda create --name <name> python=3.x
复制代码
5、克隆一个环境
conda create --name <new_name> --clone <old_name>
复制代码
6、删除某个环境
conda remove --name <name> --all
复制代码
7、conda 清空缓存
conda clean -y -all
复制代码
8、conda 镜像源
# 查看镜像源conda config --show-sources# 添加镜像源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 --remove channels https://XXX# 删除配置的镜像源,使用默认镜像源conda config --remove-key channels
复制代码
9、pip 镜像源
# 查看配置pip config list# 添加镜像源pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com# 清除缓存rm -rf ~/.cache/pip# windows 下 pip 配置文件位置C:\Users\Administrator\AppData\Roaming\pip# Linux 下 pip 配置文件位置/root/.config/pip/pip.conf
复制代码
pip 配置文件参考内容
[global]
cache-dir = D:\Environment\Miniconda3\pip\cache
index-url = https://mirrors.aliyun.com/pypi/simple/
extra-index-url=
https://pypi.tuna.tsinghua.edu.cn/simple/
http://pypi.douban.com/simple/
http://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host=
pypi.tuna.tsinghua.edu.cn
mirrors.aliyun.com
pypi.douban.com
pypi.mirrors.ustc.edu.cn
复制代码
10、导出与导入当前环境配置
conda env export > environment.yaml
conda env create -f environment.yaml
复制代码
卸载 miniconda
1、删除 miniconda3 文件夹
rm -rf ~/miniconda3/
复制代码
2、删除 .conda 文件夹和 condarc 文件
rm -rf ~/.conda
rm -rf ~/.condarc
复制代码
3、删除配置中 conda 相关
vim ~/.bashrc
复制代码
删除或注释下面这段
[code]# >>> conda initialize >>># !! Contents within this block are managed by 'conda init' !!__conda_setup="$('/root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"if [ $? -eq 0 ]; then eval "$__conda_setup"else if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then . "/root/miniconda3/etc/profile.d/conda.sh" else export PATH="/root/miniconda3/bin
PATH" fifiunset __conda_setup#
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4