md_files/Java/anaconda基础命令.md
2025-03-18 17:35:22 +08:00

137 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Anaconda基础命令
cuda版本 12.3.1 驱动版本 546.26
打开anaconda prompt普通命令行cmd也可以
**查看版本和环境**
conda -V 查看版本
conda env list 查看已安装的环境 *代表当前环境
**环境管理**
conda create -n 新环境名字 python=3.7 若只有python则下载最新版python
conda activate 新环境名字 可以切换环境
conda deactivate 退出环境到base
conda remove -n 新环境名字 --all 删除创建的环境先deactivate退出
**包管理**
*注:包管理操作前请先激活目标环境。*
conda list 列出当前环境所安装的包
conda search numpy 可以查看numpy有哪些版本
conda install numpy 可以指定版本,默认最新版
pip install -r requirements.txt (使用 pip 安装依赖包列表)
conda remove numpy 删除numpy以及所有依赖关系的包
**查看激活的环境的python版本**
python --version
**结合 PyCharm 使用 conda 环境**
在 conda 中创建好虚拟环境
如上文所示,使用 `conda create -n 新环境名字 python=版本` 创建。
在 PyCharm 中使用已有的 conda 环境
- 打开 PyCharm进入 **File > Settings > Project: YourProject > Python Interpreter**
- 点击右侧的 **Show All**,可以看到 PyCharm 已经检测到的所有解释器。
- 若没有显示目标 conda 环境,可以点击右侧的加号(+)添加现有 conda 环境作为解释器。
这是添加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环境
![image-20240729155102345](D:/folder/test/output/dd0e8c0c-08f2-4202-b137-5031b62ecb3c.png)
解决办法: shell path改为 cmd.exe
这样虚拟环境就默认设置为conda环境了
![image-20240729161200801](D:/folder/test/output/2949e4bf-056c-483b-a74e-79c95a894a77.png)
![image-20240729161242191](D:/folder/test/output/51ab0afc-4c62-418f-b90f-58816bb0aa6a.png)
如果命令行cd到项目根目录所用的也并不是conda环境这里用的是conda的默认环境
![image-20240729155148576](D:/folder/test/output/e9508c58-d415-4af5-a8e4-c6dc343d01ed.png)
正确方法:
1.使用anaconda prompt打开
2.conda activate env 激活环境
3.cd到项目根目录
4.输入命令
![image-20240729155310049](D:/folder/test/output/3245d28c-a993-4896-b419-feb7ed443f88.png)