Skip to content

Python 3 环境安装 ​

下载 ​

  • 下载 Miniconda3 Windows 64-bit 安装包

下载地址: Miniconda3 Windows 64-bit 安装包

  • 双击运行安装程序,一路 Next 即可

  • 建议勾选 Add Miniconda3 to my PATH

  • 双击运行安装程序,一路 Next 即可

  • 建议勾选 "Add Miniconda3 to my PATH"(或保持默认,之后用 Anaconda Prompt )

  • 安装完成后,打开 Anaconda Prompt (开始菜单搜索),验证:

bash
conda --version

报错 ​

方法 ​

先打开 Anaconda Prompt (开始菜单搜索 "Anaconda Prompt" 或 "Miniconda"),在里面执行:

bash
conda init powershell
  • 然后重启电脑

pip 指定包的国内镜像 ​

  • 这样下载速度快

临时使用(单次安装) ​

bash
pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple

永久配置(推荐,Windows 下 PowerShell/CMD 直接执行): ​

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

也可以手动创建配置文件%APPDATA%\pip\pip.ini : ​

ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

国内使用镜像 ​

镜像地址
清华大学(推荐)https://pypi.tuna.tsinghua.edu.cn/simple
阿里云https://mirrors.aliyun.com/pypi/simple/
中国科学技术大学https://pypi.mirrors.ustc.edu.cn/simple/
腾讯云https://mirrors.cloud.tencent.com/pypi/simple
华为云https://mirrors.huaweicloud.com/repository/pypi/simple/
豆瓣https://pypi.douban.com/simple/

建议 ​

  • 个人日常使用优先 清华(TUNA) 或 中科大(USTC) ,稳定且同步及时
  • 云服务器上选对应厂商的源(阿里云机器用阿里云源可走内网,速度更快)
  • 豆瓣源历史上偶尔不稳定,可作备用
  • 主源不可用时可以组合使用:pip install 包名 -i 清华源 --extra-index-url 阿里云源

创建虚拟环境 ​

bash

# 查看所有环境
conda env list

# 默认basse环境 安装uv

# 用 pip 装 uv

pip install uv

# 验证

uv --version

# 创建一个名为 fastapi-env、Python 3.11 的环境
conda create -n fastapi-env python=3.11 -y

# 激活环境
conda activate fastapi-env



# 查看Python版本

conda list -n fastapi-env python

初始化虚拟环境 ​

bash
# 初始化虚拟环境
uv init --no-package

安装包命令 ​

bash
uv add 包名

启动项目 ​

bash
uv run 项目名.py

重新安装所有的依赖 ​

  • 重新安装所有的依赖
bash
uv sync

删除包 ​

bash
uv remove 包名

常用命令 ​

bash
# 查看所有环境
conda env list

# 退出当前环境
conda deactivate

# 退出虚拟环境
conda deactivate

# 删除环境
conda remove -n fastapi-env --all -y

# 在激活的环境中安装包(例如 FastAPI)
pip install fastapi uvicorn


# 或用 conda 安装
conda install -c conda-forge fastapi

# 使用uv 安装包我这里就是安装了reqeust
uv add request