一、安装
安装地址
国内使用清华镜像站下载
Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
更换清华镜像源
教程地址
anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
1.Windows 用户无法直接创建名为 .condarc
的文件,可以先执行
conda config --set show_channel_urls yes
在这个路径下(C:\Users\KLJ2004)就可以找到.condarc文件
2.使用记事本编辑
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
3.清楚索引缓存
conda clean -i
二、一些常用的命令
创建虚拟环境
conda create -n 环境名 python=python版本
这些是默认安装的
删除虚拟环境
conda remove -n 环境名 --all
会把环境中存在的包列出来,输入y回车就可以了
查看已经创建的环境(当前所在的环境上面会有一个*号标明)
conda env list
切换到某个环境
conda activate 环境名
退出当前环境
conda deactivate
查看当前环境已经安装的包
conda list
卸载包
pip uninstall 包名
这里拿argon2-cffi演示,再次列出包列表,成功删除
查看镜像配置
conda config --show channels
三、一些常用库的安装
Pytorch的安装(GPU)
1.安装CUDA
2.Anaconda安装一些对应的库
找到torch,torchvision,torchaudio的对应版本,然后直接在Anaconda Prompt里面输入
pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0 -f https://download.pytorch.org/whl/torch_stable.html
这篇文章有一些对应版本
【torch、torchvision、torchaudio】版本对应关系_torchaudio版本对应-CSDN博客
也可以在这里看
Installing pre-built binaries — Torchaudio 2.2.0.dev20240427 documentation
3.查看是否安装成功,显示true就安装成功了
CVXPY安装
1.直接安就行了,这个模块有很多的依赖包(比如numpy),会自动一起安了的
pip install cvxpy
2.在运行的时候可能是会包求解器的错误
prob.solve(solver='GLPK_MI')
直接在Anaconda prompt里面安装就行了
pip install cvxpy[GLPK_MI]
错误解决
四、Jupyter-notebook
1.如何切换环境
在cv_env环境中直接打开以后,在Kernel是找不到这个环境的
这是因为新环境里面没有jupyter-notebook,执行以下命令
conda install nb_conda
再次打开以后在Kernel中成功找到当前环境
2.如何修改工程文件的目录位置(只修改快捷方式的属性也可以,只做第1步和第4步也可以的)
1.创建一个要放的目录
2.在命令行窗口输入
jupyter notebook --generate-config
就可以找到jupyter的配置文件.jupyter\jupyter_notebook_config.py的位置
3.根据位置找到配置文件,用记事本打开,并进行修改(查找ctrl+F)
c.NotebookApp.notebook_dir
取消注释,并修改
最后不要忘记ctrl+s保存
4.找到jupyter的快捷方式,右键找到属性打开,在目标中"%USERPROFILE%/"前面添加文件路径(我的是E:\code\jupyter_python\base)
注意前后要有空格,不然jupyter就打不开了
5.新建一个脚本,打开设置的目录就有了