miniconda入门使用

文章目录

相关环境变量PATH与PYTHONPATH

PATH

这个是操作系统找可执行程序,他决定了在终端输入命令时从哪里找这些对应的命令

干净的PATH

bash 复制代码
tianbot@ros2go:~$ echo ${PATH}
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

使用管道+替换查看

bash 复制代码
tianbot@ros2go:~$ echo ${PATH} | tr ':' '\n'
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

对于终端上的一个命令,系统的查找顺序是由上至下的

1、/usr/local/sbin(sbin = system binary)

系统管理员安装的系统管理程序。

2、/usr/local/bin

管理员手动安装的软件。

3、/usr/sbin

系统自带的管理员程序。

4、/usr/bin

最主要的目录。

5、/sbin

系统启动或维护程序

6、/bin

最基础的系统命令。

7、/usr/games

8、/usr/local/games

9、/snap/bin

增加PATH

使用export声明环境变量

使用新目录+:的形式可以添加新目录

bash 复制代码
export PATH=新目录:$PATH

在miniconda当中就会添加

bash 复制代码
export PATH="/home/user/miniconda3/bin:$PATH"

PYTHONPATH

这个是启动python时,找相关的包/模块

比如import一个包

python 复制代码
import numpy

Python会按顺序查找:

1 当前目录

2 PYTHONPATH里的路径

3 site-packages---Python安装目录

4.系统Python库

conda环境激活

临时激活

bash 复制代码
source ~/miniconda3/etc/profile.d/conda.sh

加载shell脚本之后就可以使用conda命令了

配置.bashrc(每次打开终端自动激活)

bash 复制代码
~/miniconda3/bin/conda init

运行之后会在~/bashrc当中自动添加

bash 复制代码
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/tianbot/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/tianbot/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/tianbot/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/tianbot/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

这样每次打开终端时都会激活conda环境了

conda的常用命令

查看环境

bash 复制代码
conda env list

*:当前激活环境

创建环境

bash 复制代码
conda create -n myenv python=3.10
参数 含义
create 创建环境
-n 环境名称
python=3.10 指定 Python 版本

激活环境

bash 复制代码
conda activate myenv

这时候终端前面会有一个小括号里面写着环境

退出环境

bash 复制代码
conda deactivate

这时候会回到bash环境

在环境当中安装包

bash 复制代码
conda install numpy

删除

命令 作用
conda remove 包名 删除包
conda remove -n 环境名 --all 删除环境
conda env remove -n 环境名 删除环境(推荐)
bash 复制代码
conda remove -n myenv --all

查看当前环境(里面的)当中的包

bash 复制代码
conda list 

不想每次开终端自动进入 base 环境

bash 复制代码
conda config --set auto_activate_base false
相关推荐
IT知识分享16 分钟前
从零开发在线简繁转换工具:OpenCC 实战、避坑经验与方案选型
javascript·python
lunzi_082621 分钟前
【学习笔记】《Python编程 从入门到实践》第8章:函数定义、参数传递与模块导入
笔记·python·学习
杨运交38 分钟前
[030][Web模块]Spring Boot 验证与 OpenAPI 集成实战:从校验规则到文档生成
前端·spring boot·python
培培说证1 小时前
2026财务岗位如何快速提升自身能力
python
努力攻坚操作系统1 小时前
编程语言编译运行机制对比:C / Java / Python
java·c语言·python
godspeed_lucip1 小时前
LLM和Agent——专题6:Multi Agent 入门(5)
人工智能·python
Metaphor6922 小时前
使用 Python 给 PDF 设置背景色或背景图
数据库·python·pdf
郝亚军2 小时前
如何让pycharm-2026.1.2顶部菜单栏固定显示在最上端
python
怪兽学LLM3 小时前
LeetCode 438 找到字符串中所有字母异位词(Python 固定滑动窗口+字符计数解法)
python·算法·leetcode