Administrator
发布于 2026-05-17 / 5 阅读
0

Anaconda

Anaconda 设置国内镜像

  • 临时使用

    
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
    
    # 注意,simple 不能少, 是 https 而不是 http
    
    

设为默认


# 升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

  • 如果到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

    
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
    
    

环境变量


anaconda3/Scripts

anaconda3/Library/bin

anaconda3/library/mingw-64/bin

linux:export PATH=$PATH:/home/software/anaconda3/bin



此时配置完成 操作时主要是用 conda.exe conda.bat

常用命令


# 环境变量设置 查看

conda env config vars list

# 添加

conda env config vars set xxx=yyy -n envname

# 删除环境变量

conda env config vars unetset xxx


# 查看所有的虚拟环境

conda info --envs

# 创建tensorflow虚拟环境

conda create -n tensorflow(只是个名字) python=3.7.3 #(根据ananconda的版本决定)

# 删除环境

conda remove -n envname --all

conda activate tensorflow #进入tensorflow 虚拟环境

# 安装tensorflow

pip install tensorflow-gpu==版本号

conda deactivate 退出虚拟环境

# 克隆环境

conda create --name clone_env --clone old_name

# 查看当前换件中安装的所有包

conda list

# 查看指定虚拟环境中安装的所有包

conda list -n envname

# 更新指定包

conda update unmpy

# 更新所有包

conda update

# 更新python

conda update python

# 更新conda本身

conda update conda

# 更新conda库

conda update conda

# 更新anaconda版本

conda update anaconda

# 升级

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow 

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade tensorflow-gpu 


# channel状态与优先级

conda config --get channels

# 设置通道(默认的defaults无法使用了)

conda config --add channels conda-forge # https://conda-forge.org/docs/index.html

配置condarc,就不用配置pip


配置文件:~/.condarc

channels:

  - defaults

show_channel_urls: true

channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda

default_channels:

  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro

  - 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

  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

所有的包都可以安装,安装都是到虚拟环境了,cuda库(高性能计算),cudnn库(深度学习),都可以通过conda 安装到虚拟环境,不需要英伟达官方下载,

conda 一般用来安装那些C库,conda search xx 找不到时,可用 conda search xx -c conda-forge,通过源找就可以。

注:安装tensorflow,pytorch


pytorch,安装时只用安装pytorch,cudatoolkit,不用cudnn,pytorch自带了

tensorflow,新版本的tensorflow,gpu,cpu合并了,安装tensorflow,cudatoolkit,cudnn,即可

# 显卡驱动(独立安装的),python,tensorflow,cudatoolkit,cudnn之间对应关系

Jupyter


jupyter notebook  --generate-config	# 生成配置文件

cNotebookApp.notebook_dir="xxx"		# 修改默认路径

conda create -n py3 python=3		# 创建一个python3的环境,名为py3

source activate py3					# 激活py3环境

conda install ipykernel				# 安装ipykernel模块

python -m ipykernel install --user --name=py3 # 进行配置

jupyter notebook 					# 启动jupyter notebook then can choose python environment

注意tensorflow版本与python,cuda对应关系

Conda与pip

  • conda可以安装C库Python库,直接通过二进制安装

  • pip只能安装python包,编译安装,config set global.index-url 指定源

    
     pip config list # 显示pip安装源
    
    

镜像

可能失效


channels:

  - defaults

show_channel_urls: true

default_channels:

  - http://mirrors.aliyun.com/anaconda/pkgs/main

  - http://mirrors.aliyun.com/anaconda/pkgs/r

  - http://mirrors.aliyun.com/anaconda/pkgs/msys2

custom_channels:

  conda-forge: http://mirrors.aliyun.com/anaconda/cloud

  msys2: http://mirrors.aliyun.com/anaconda/cloud

  bioconda: http://mirrors.aliyun.com/anaconda/cloud

  menpo: http://mirrors.aliyun.com/anaconda/cloud

  pytorch: http://mirrors.aliyun.com/anaconda/cloud

  simpleitk: http://mirrors.aliyun.com/anaconda/cloud



envs_dirs:

  - D:\ProgramOfMine\Language\Python



pkgs_dirs:

  - D:\ProgramOfMine\Language\Python\conda