Conda使用技巧总结

Conda使用技巧总结

使用国内镜像下载Python包

一般国内镜像有:

豆瓣镜像源https://pypi.douban.com/simple/

清华大学镜像源

华为云镜像源

阿里云镜像源

临时在使用pip的时候加参数-i
例如:pip install pandas==2.10 -i https://pypi.tuna.tsinghua.edu.cn/simple

使用Miniconda替换Anaconda

之前一直使用的是anaconda,使用方便,一些基础包都有,但是随着使用时间,感觉anaconda占用系统空间太大了,后来发现miniconda作用和anaconda一样,安装空间占用只有50M,建议安装miniconda3 64bit python3.7版本的,官网下载安装地址

下载安装后,配置系统环境

D:\Miniconda3 
D:\Miniconda3\Scripts 
D:\Miniconda3\Library\bin 
将以上miniconda安装包的路径添加到系统环境中,一边我们在cmd中直接可以使用

更改镜像下载源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

创建conda虚拟环境

虚拟环境作用

每个项目对应一个单独的虚拟环境,这样使用的Python包文件都在一个单独的项目环境里,方便管理

conda基本命令

换源:因为默认是anaconda国外,有时候比较慢,可以国内镜像,比如清华源
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/msys2/

查看源:conda info


恢复默认源:conda config --remove-key channels
安装包:conda install XXX 或者 pip install XXX (我一般用pip安装)
更新包:conda update XXX 或者 pip install --upgrade XXX (用pip安装就用pip更新)
卸载包:conda uninstall XXX 或者 pip uninstall XXX (用pip安装就用pip卸载)
查看安装包列表:conda list 或者 pip list (注意conda list会显示哪些是pip安装的)
创建虚拟环境:conda create -n 虚拟环境名xxx python=3.7(其中XXX是环境名字,要注意如果python版本只写到3.7,会默认使用最新的3.7.10版本。)
查看虚拟环境列表:conda env list
激活虚拟环境:conda activate XXX
退出conda环境:conda deactivate XXX (这个xxx可以不写)
删除虚拟环境:conda remove -n XXX --all

导出项目中所有python包名称参考

#导出所有环境的Python包文件名
pip freeze > requirements.txt

#先下载包
pip install pipreqs
#只导出虚拟环境中的依赖包
pipreqs ./

批量下载安装requirements.txt python包

#使用国内镜像安装python包
pip install -i https://pypi.doubanio.com/simple/ -r requirements.txt

下载jupyter notebook

pip install jupyter notebook -i https://pypi.douban.com/simple/

posted @ 2023-06-24 19:32  Pyscm  阅读(193)  评论(0)    收藏  举报