mac安装 python,LangChain----ai开发

1、安装uv

优先安装uv,官方独立脚本,避免brew的坑

curl -LsSf https://astral.sh/uv/install.sh | sh

2、配置path

写入zsh永久环境变量

echo 'export PATH="HOME/.local/bin:PATH"' >> ~/.zshrc

重载配置生效

source ~/.zshrc

验证

uv --version uvx --version

3、配置镜像

mkdir -p ~/.config/uv

nano ~/.config/uv/uv.toml

镜像配置

默认pip源 清华

\[index\]

url = "https://pypi.tuna.tsinghua.edu.cn/simple"

default = true

备用阿里源

\[index\]

url = "https://mirrors.aliyun.com/pypi/simple"

Python官方二进制国内镜像(uv python install加速)

python-install-mirror = "https://mirror.nju.edu.cn/github-release/astral-sh/python-build-standalone/"

并发下载提速

concurrency

downloads = 12

保存:Ctrl+O 回车 → Ctrl+X

4、安装python

安装稳定版3.12(LangChain开发首选)

uv python install 3.12

查看本地所有

Python uv python list

设置全局默认

Python uv python pin 3.12

5、查看版本

uv run python --version

6、安装PyCharm

7、创建项目

8、终端进入项目,安装依赖

cd xxxxx

uv add langchain

Requires Python 3.10+

Installing the OpenAI integration

uv add langchain-openai

Installing the Anthropic integration

uv add langchain-anthropic