2025-03-18 17:35:22 +08:00
|
|
|
|
## Anaconda基础命令
|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda版本 12.3.1 驱动版本 546.26
|
|
|
|
|
|
|
|
|
|
打开anaconda prompt(普通命令行cmd也可以):
|
2025-03-18 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
**查看版本和环境**
|
|
|
|
|
|
2025-03-18 12:46:59 +08:00
|
|
|
|
conda -V 查看版本
|
|
|
|
|
conda env list 查看已安装的环境 *代表当前环境
|
2025-03-18 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**环境管理**
|
|
|
|
|
|
2025-03-18 12:46:59 +08:00
|
|
|
|
conda create -n 新环境名字 python=3.7 (若只有python则下载最新版python)
|
|
|
|
|
conda activate 新环境名字 可以切换环境
|
|
|
|
|
conda deactivate 退出环境到base
|
2025-03-18 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
conda remove -n 新环境名字 --all 删除创建的环境(先deactivate退出)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**包管理**
|
|
|
|
|
|
|
|
|
|
*注:包管理操作前请先激活目标环境。*
|
|
|
|
|
|
|
|
|
|
conda list 列出当前环境所安装的包
|
|
|
|
|
|
2025-03-18 12:46:59 +08:00
|
|
|
|
conda search numpy 可以查看numpy有哪些版本
|
|
|
|
|
conda install numpy 可以指定版本,默认最新版
|
2025-03-18 17:35:22 +08:00
|
|
|
|
pip install -r requirements.txt (使用 pip 安装依赖包列表)
|
2025-03-18 12:46:59 +08:00
|
|
|
|
conda remove numpy 删除numpy以及所有依赖关系的包
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-18 17:35:22 +08:00
|
|
|
|
**查看激活的环境的python版本**
|
|
|
|
|
|
|
|
|
|
python --version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**结合 PyCharm 使用 conda 环境**
|
|
|
|
|
|
|
|
|
|
在 conda 中创建好虚拟环境
|
|
|
|
|
如上文所示,使用 `conda create -n 新环境名字 python=版本` 创建。
|
|
|
|
|
|
|
|
|
|
在 PyCharm 中使用已有的 conda 环境
|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
2025-03-18 17:35:22 +08:00
|
|
|
|
- 打开 PyCharm,进入 **File > Settings > Project: YourProject > Python Interpreter**
|
|
|
|
|
- 点击右侧的 **Show All**,可以看到 PyCharm 已经检测到的所有解释器。
|
|
|
|
|
- 若没有显示目标 conda 环境,可以点击右侧的加号(+)添加现有 conda 环境作为解释器。
|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
这是添加conda镜像
|
|
|
|
|
|
|
|
|
|
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
|
|
|
|
|
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
|
|
|
|
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
|
|
|
|
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
|
|
|
|
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/mysys2/
|
|
|
|
|
conda config --set show_channel_urls yes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
这是添加Pypi镜像,适用于pip安装
|
|
|
|
|
|
|
|
|
|
清华:https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
|
|
|
|
|
|
阿里云:https://mirrors.aliyun.com/pypi/simple/
|
|
|
|
|
|
|
|
|
|
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
|
|
|
|
|
|
|
|
|
|
华中理工大学:https://pypi.hustunique.com/
|
|
|
|
|
|
|
|
|
|
山东理工大学:https://pypi.sdutlinux.org/
|
|
|
|
|
|
|
|
|
|
豆瓣:https://pypi.douban.com/simple/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在conda中导出pip requirements.txt:
|
|
|
|
|
|
|
|
|
|
pip freeze > requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Conda环境与Pycharm环境的大坑
|
|
|
|
|
|
|
|
|
|
如果你的pycharm中使用conda环境,那么你在pycharm的终端中所用的可能不是conda环境!
|
|
|
|
|
|
2025-03-19 18:31:37 +08:00
|
|
|
|

|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
解决办法: shell path改为 cmd.exe
|
|
|
|
|
这样虚拟环境就默认设置为conda环境了
|
|
|
|
|
|
2025-03-19 18:31:37 +08:00
|
|
|
|

|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
2025-03-19 18:31:37 +08:00
|
|
|
|

|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
如果命令行cd到项目根目录,所用的也并不是conda环境!这里用的是conda的默认环境?
|
|
|
|
|
|
2025-03-19 18:31:37 +08:00
|
|
|
|

|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
正确方法:
|
|
|
|
|
|
|
|
|
|
1.使用anaconda prompt打开
|
|
|
|
|
|
|
|
|
|
2.conda activate env 激活环境
|
|
|
|
|
|
|
|
|
|
3.cd到项目根目录
|
|
|
|
|
|
|
|
|
|
4.输入命令
|
|
|
|
|
|
2025-03-19 18:31:37 +08:00
|
|
|
|

|
2025-03-18 12:46:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|