conda安装和镜像源配置
# 安装
Miniconda清华源 (opens new window)
bash Miniconda-3.9.1-Linux-x86_64.sh -b -u -p /usr/local/miniconda3
1
# 配置
#生成配置文件
conda config
1
2
2
# 查看当前源
conda config --show channels
1
# 替换源
conda config --add channels https://xxxxxxxxxxxxxxx
1
针对清华源和腾讯源替换的方法
清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
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/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
1
2
3
4
5
2
3
4
5
腾讯源
conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/
conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/
conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/pro/
1
2
3
4
5
2
3
4
5
# 移除源
conda config --remove channels https://xxxxxxxxxxxxxxx
1
针对清华源和腾讯源移除的方法
清华源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
1
2
3
4
5
2
3
4
5
腾讯源
conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/
conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/
conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/cloud/conda-forge/
conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/cloud/pytorch/
conda config --remove channels https://mirrors.cloud.tencent.com/anaconda/pkgs/pro/
1
2
3
4
5
2
3
4
5
# 使用配置文件修改
使用文档编辑工具打开 ~/.condarc 文件,即可手动修改配置信息。
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
- defaults
show_channel_urls: true
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 使用 conda
创建一个新的虚拟环境,并安装兼容的 Python 版本
conda create -n tf2 python=3.9
conda activate tf2
1
2
2
# 导出现有环境的python依赖
python -m pip freeze > requirements.txt
pip install -r requirements.txt
#指定镜像源安装
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
1
2
3
4
2
3
4
# 在 Windows 系统上运行 Python 应用,创建虚拟环境(virtual environment)的方法很简单。这里是标准步骤:
# 1. 安装 Python
确认你已经安装了 Python,并且安装时勾选了 "Add Python to PATH"。
可以打开命令行(cmd
)输入:
python --version
1
确认能看到版本号。
# 2. 安装 virtualenv
(可选)
虽然 Python 3.3+ 自带了 venv
模块,不需要额外安装,但有些人喜欢用 virtualenv
。如果想用它,可以安装:
pip install virtualenv
1
# 3. 使用 venv
创建虚拟环境(推荐)
在你的项目目录下,比如 D:\myproject
,打开命令行,运行:
cd D:\myproject
python -m venv venv
1
2
2
这会在 D:\myproject\venv\
目录里创建一个虚拟环境。
# 4. 启动虚拟环境
在 Windows 上激活虚拟环境,命令是:
venv\Scripts\activate
1
激活后,命令行前面会出现 (venv)
,表示虚拟环境已经启用。
# 5. 安装依赖
虚拟环境激活后,你可以用 pip 安装项目需要的库,比如:
pip install -r requirements.txt
1
# 6. 退出虚拟环境
用完之后,退出虚拟环境,可以输入:
deactivate
1


上次更新: 2025/04/27, 17:35:39