【基础】Python 环境搭建

Python 环境搭建教程(Windows + VS Code + Anaconda)

课程概述

本教程指导智能网联小组成员在 Windows 上完成 Python 开发环境的标准化搭建:使用 Anaconda 管理 Python 版本与虚拟环境,配置国内镜像以加速下载,集成 VS Code 进行开发。

学习目标

  • 了解并安装 Anaconda,完成基础配置
  • 使用 conda 创建、管理
  • 配置 pip/conda 国内镜像
  • 在 VS Code 中选择解释器、运行与调试 Python

目录


第一章:Anaconda 安装与配置(Windows)

1.1 下载与安装

  • 下载资料库中的 Anaconda3-2022.05-Windows-x86_64.exe 并执行安装

1.2 安装步骤

  1. 双击安装包,勾选“为当前用户安装”,并且安装路径不准有中文,默认即可。

在这里插入图片描述在这里插入图片描述

  1. 推荐“Add Anaconda to my PATH”和“Register Anaconda as my default Python”都勾选上。

在这里插入图片描述

  1. 完成安装后关闭向导。

在这里插入图片描述
在这里插入图片描述

1.3 环境变量与启动方式

  • 通过“搜索 → Anaconda Prompt”启动自带终端,默认已激活 base 环境。
    在这里插入图片描述

在这里插入图片描述

1.4 安装后验证

conda --version
python --version
where python
  • 期望:看到 conda 版本与 Python 版本,where python 指向 Anaconda 路径。
    在这里插入图片描述

第二章:conda 环境管理

2.1 创建与查看环境

# 创建名为 py38 的环境,并指定 Python 版本
conda create -n py38 python=3.8 -y

# 列出所有环境
conda env list

# 激活 / 退出环境
conda activate py38
conda deactivate

2.2 安装与卸载包

# 在当前环境安装常用包
conda install numpy matplotlib -y

# 使用 pip 安装(当前环境)
pip install requests

# 升级与卸载
pip install --upgrade requests
pip uninstall requests -y

2.4 常用命令速查

操作命令示例
创建环境conda create -n <环境名> python=3.10 -y
切换环境conda activate <环境名>
删除环境conda remove -n <环境名> --all -y
查询包conda listpip list
安装包conda install <包名>pip install <包名>

第三章:pip 与 conda 镜像配置

3.1 pip 临时与全局镜像

# 临时使用镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -U pip

3.2 conda 通道(channels)与国内镜像

# 查看通道优先级与已配置通道
conda config --show channels
conda config --show channel_priority

# 添加清华镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --set show_channel_urls yes

#或者使用以下镜像

# 清华镜像源
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.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
# 上海交大镜像源
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
# 北外镜像源
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge/

第四章:VS Code 集成与调试

4.1 安装 VS Code

  • 下载资料库中的 VSCodeUserSetup-x64-1.104.3.exe 并执行安装,安装目录不能有中文,最好默认
    在这里插入图片描述

4.2 VS Code 安装中文语言包

1.点击左边拓展按钮
2.搜索Chinese并点击install
3.搜索Python并点击install
3.安装完成后关闭VS Code,重新打开

在这里插入图片描述
在这里插入图片描述

4.3 创建项目文件和Python测试文件

  1. 在桌面上创建一个文件夹,并使用vscode打开

在这里插入图片描述在这里插入图片描述在这里插入图片描述

  1. 打开命令面板(Ctrl+Shift+P)输入“Python: Select Interpreter”。

在这里插入图片描述

  1. 选择目标 conda 环境对应的解释器(显示环境名称)。

在这里插入图片描述

4.4 运行与调试脚本

print("hello, conda env")
  • 运行:右上角运行按钮或终端 python main.py

在这里插入图片描述
在这里插入图片描述


教程更新时间: [2025年10月13日]
编写者: [华灿宽]
版本: v1.0


*本教程为智能网联汽车基础培训系列配套教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hihck

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值