python3t pip3安装langchain失败心得

前言

最近在做poc,python一定是最方便的方式,毕竟不追求性能,但是笔者以前使用ollama玩的时候使用了python3t,自由线程版本,这个就为后面的项目趟坑了,langchain1.x不支持自由线程,更准确的说是orjson不支持,当然不排除以后就支持了,顺便总结一下安装的心得,怎么排查出现的问题。

安装心得

根据官网:安装 | LangChain 中文文档

直接安装

直接执行pip3 install langchain,笔者已经配置清华源,也尝试了阿里源,结果一直卡在这里

Preparing metadata (pyproject.toml)

然后搜索结果,说可以加verbose参数,打印日志

分析日志

pip3 install --verbose langchain

尝试换源

pip3 install --verbose langchain -i https://mirrors.aliyun.com/pypi/simple

bash 复制代码
  Installing backend dependencies ... done
  Running command Preparing metadata (pyproject.toml)
  Python reports SOABI: cpython-314t-darwin
  Computed rustc target triple: aarch64-apple-darwin
  Installation directory: /Users/huahua/Library/Caches/puccinialin
  Rustup already downloaded
  Installing rust to /Users/huahua/Library/Caches/puccinialin/rustup
  warn: It looks like you have an existing rustup settings file at:
  warn: /Users/huahua/Library/Caches/puccinialin/rustup/settings.toml
  warn: Rustup will install the default toolchain as specified in the settings file,
  warn: instead of the one inferred from the default host triple.
  info: profile set to minimal
  info: setting default host triple to aarch64-apple-darwin
  warn: Updating existing toolchain, profile choice will be ignored
  info: syncing channel updates for stable-aarch64-apple-darwin
  info: latest update on 2026-07-09 for version 1.97.0 (2d8144b78 2026-07-07)
  info: recovering from a partially installed toolchain
  info: removing previous version of component rustc
  info: removing previous version of component cargo
  info: removing previous version of component rust-std
  info: removing previous version of component rust-docs
  info: removing previous version of component rustfmt
  info: removing previous version of component clippy
  info: downloading 6 components

卡在downloading这里,并不是前面的错误

尝试搜索解决

搜索一下

安装后brew install python-tk

bash 复制代码
Installing backend dependencies ... done
  Running command Preparing metadata (pyproject.toml)
  Python reports SOABI: cpython-314t-darwin
  Computed rustc target triple: aarch64-apple-darwin
  Installation directory: /Users/huahua/Library/Caches/puccinialin
  Rustup already downloaded
  Installing rust to /Users/huahua/Library/Caches/puccinialin/rustup
  warn: It looks like you have an existing rustup settings file at:
  warn: /Users/huahua/Library/Caches/puccinialin/rustup/settings.toml
  warn: Rustup will install the default toolchain as specified in the settings file,
  warn: instead of the one inferred from the default host triple.
  info: profile set to minimal
  info: setting default host triple to aarch64-apple-darwin
  warn: Updating existing toolchain, profile choice will be ignored
  info: syncing channel updates for stable-aarch64-apple-darwin
  info: default toolchain set to stable-aarch64-apple-darwin
  Checking if cargo is installed
  cargo 1.97.0 (c980f4866 2026-06-30)
  📦 Including license file `LICENSE-APACHE`
  📦 Including license file `LICENSE-MIT`
  📦 Including license file `LICENSE-MPL-2.0`
  🍹 Building a mixed python/rust project
  🐍 Found CPython 3.14t at /Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python
  🔗 Found pyo3-ffi bindings
  orjson-3.11.9.dist-info
  Checking for Rust toolchain....
  Rust not found, installing into a temporary directory
  Running `maturin pep517 write-dist-info --metadata-directory /private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-modern-metadata-k11tg7hz --interpreter /Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python`
  Preparing metadata (pyproject.toml) ... done
Collecting websockets<16,>=14 (from langgraph-sdk<0.5.0,>=0.4.2->langgraph<1.3.0,>=1.2.5->langchain)
  Using cached websockets-15.0.1-py3-none-any.whl (169 kB)
Collecting anyio>=3.5.0 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached anyio-4.14.2-py3-none-any.whl (125 kB)
Collecting distro>=1.7.0 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached distro-1.9.0-py3-none-any.whl (20 kB)
Collecting requests-toolbelt>=1.0.0 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
Collecting requests>=2.0.0 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached requests-2.34.2-py3-none-any.whl (73 kB)
Collecting sniffio>=1.1 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached sniffio-1.3.1-py3-none-any.whl (10 kB)
Collecting zstandard>=0.23.0 (from langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached zstandard-0.25.0-cp314-cp314t-macosx_10_15_universal2.whl
Collecting certifi (from httpx>=0.25.2->langgraph-sdk<0.5.0,>=0.4.2->langgraph<1.3.0,>=1.2.5->langchain)
  Using cached certifi-2026.6.17-py3-none-any.whl (133 kB)
Collecting httpcore==1.* (from httpx>=0.25.2->langgraph-sdk<0.5.0,>=0.4.2->langgraph<1.3.0,>=1.2.5->langchain)
  Using cached httpcore-1.0.9-py3-none-any.whl (78 kB)
Collecting idna (from httpx>=0.25.2->langgraph-sdk<0.5.0,>=0.4.2->langgraph<1.3.0,>=1.2.5->langchain)
  Using cached idna-3.18-py3-none-any.whl (65 kB)
Collecting h11>=0.16 (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.5.0,>=0.4.2->langgraph<1.3.0,>=1.2.5->langchain)
  Using cached h11-0.16.0-py3-none-any.whl (37 kB)
Collecting annotated-types>=0.6.0 (from pydantic<3.0.0,>=2.7.4->langchain)
  Using cached annotated_types-0.7.0-py3-none-any.whl (13 kB)
Collecting pydantic-core==2.46.4 (from pydantic<3.0.0,>=2.7.4->langchain)
  Using cached pydantic_core-2.46.4-cp314-cp314t-macosx_11_0_arm64.whl (1.9 MB)
Collecting typing-inspection>=0.4.2 (from pydantic<3.0.0,>=2.7.4->langchain)
  Using cached typing_inspection-0.4.2-py3-none-any.whl (14 kB)
Collecting charset_normalizer<4,>=2 (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached charset_normalizer-3.4.9-cp314-cp314t-macosx_10_15_universal2.whl (338 kB)
Collecting urllib3<3,>=1.26 (from requests>=2.0.0->langsmith<1.0.0,>=0.3.45->langchain-core<2.0.0,>=1.4.9->langchain)
  Using cached urllib3-2.7.0-py3-none-any.whl (131 kB)
Building wheels for collected packages: orjson
  Running command Building wheel for orjson (pyproject.toml)
  Python reports SOABI: cpython-314t-darwin
  Computed rustc target triple: aarch64-apple-darwin
  Installation directory: /Users/huahua/Library/Caches/puccinialin
  Rustup already downloaded
  Installing rust to /Users/huahua/Library/Caches/puccinialin/rustup
  warn: It looks like you have an existing rustup settings file at:
  warn: /Users/huahua/Library/Caches/puccinialin/rustup/settings.toml
  warn: Rustup will install the default toolchain as specified in the settings file,
  warn: instead of the one inferred from the default host triple.
  info: profile set to minimal
  info: setting default host triple to aarch64-apple-darwin
  warn: Updating existing toolchain, profile choice will be ignored
  info: syncing channel updates for stable-aarch64-apple-darwin
  info: default toolchain set to stable-aarch64-apple-darwin
  Checking if cargo is installed
  cargo 1.97.0 (c980f4866 2026-06-30)
  Rust not found, installing into a temporary directory
  Running `maturin pep517 build-wheel -i /Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python --compatibility off`
  📦 Including license file `LICENSE-APACHE`
  📦 Including license file `LICENSE-MIT`
  📦 Including license file `LICENSE-MPL-2.0`
  🍹 Building a mixed python/rust project
  🐍 Found CPython 3.14t at /Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python
  🔗 Found pyo3-ffi bindings
  💻 Using `MACOSX_DEPLOYMENT_TARGET=11.0` for aarch64-apple-darwin by default
     Compiling target-lexicon v0.13.5
     Compiling serde_core v1.0.228
     Compiling libc v0.2.186
     Compiling zmij v1.0.21
     Compiling find-msvc-tools v0.1.9
     Compiling shlex v1.3.0
     Compiling serde_json v1.0.149
     Compiling serde v1.0.228
     Compiling memchr v2.8.0
     Compiling cfg-if v1.0.4
     Compiling itoa v1.0.18
     Compiling cc v1.2.61
     Compiling encoding_rs v0.8.35
     Compiling simdutf8 v0.1.5
     Compiling bytecount v0.6.9
     Compiling jiff v0.2.24
     Compiling bytes v1.11.1
     Compiling once_cell v1.21.4
     Compiling xxhash-rust v0.8.15
     Compiling associative-cache v3.0.1
     Compiling itoap v1.0.1
     Compiling pyo3-build-config v0.28.3
     Compiling pyo3-ffi v0.28.3
     Compiling orjson v3.11.9 (/private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-install-7qni62om/orjson_1e6569c10f884d6082067fb020c1bfef)
  error: failed to run custom build command for `orjson v3.11.9 (/private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-install-7qni62om/orjson_1e6569c10f884d6082067fb020c1bfef)`

  Caused by:
    process didn't exit successfully: `/private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-install-7qni62om/orjson_1e6569c10f884d6082067fb020c1bfef/target/release/build/orjson-5d5083e97483966b/build-script-build` (exit status: 1)
    --- stderr



    orjson v3.11.9 does not support free-threaded Python



  💥 maturin failed
    Caused by: Failed to build a native library through cargo
    Caused by: Cargo build finished with "exit status: 101": `env -u CARGO CARGO_ENCODED_RUSTFLAGS="-C\u{1f}link-arg=-undefined\u{1f}-C\u{1f}link-arg=dynamic_lookup" MACOSX_DEPLOYMENT_TARGET="11.0" PYO3_BUILD_EXTENSION_MODULE="1" PYO3_ENVIRONMENT_SIGNATURE="cpython-3.14-64bit" PYO3_PYTHON="/Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python" PYTHON_SYS_EXECUTABLE="/Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python" "cargo" "rustc" "--profile" "release" "--message-format" "json-render-diagnostics" "--manifest-path" "/private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-install-7qni62om/orjson_1e6569c10f884d6082067fb020c1bfef/Cargo.toml" "--lib" "--" "-C" "link-args=-Wl,-install_name,@rpath/orjson.cpython-314t-darwin.so"`
  Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
  error: subprocess-exited-with-error
  
  × Building wheel for orjson (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> No available output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /Users/huahua/PycharmProjects/langchain-demo/.venv/bin/python /Users/huahua/PycharmProjects/langchain-demo/.venv/lib/python3.14t/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/tmpdfjck19y                                                        
  cwd: /private/var/folders/ns/lcvjv08118n60db8ry41jjvw0000gn/T/pip-install-7qni62om/orjson_1e6569c10f884d6082067fb020c1bfef
  Building wheel for orjson (pyproject.toml) ... error
  ERROR: Failed building wheel for orjson
Failed to build orjson                                                                                                                                                     
error: failed-wheel-build-for-install

× Failed to build installable wheels for some pyproject.toml based projects
╰─> orjson

又前进了一大步

分析工具

orjson v3.11.9 does not support free-threaded Python

看来自由线程的版本太"先进",改为常规版本试试

切换后安装成功

bash 复制代码
Successfully installed charset_normalizer-3.4.9 distro-1.9.0 jsonpatch-1.33 jsonpointer-3.1.1 langchain-1.3.13 langchain-core-1.4.9 langchain-protocol-0.0.18 langgraph-1.2.9 langgraph-checkpoint-4.1.1 langgraph-prebuilt-1.1.0 langgraph-sdk-0.4.2 langsmith-0.10.3 orjson-3.11.9 ormsgpack-1.12.2 packaging-26.2 pyyaml-6.0.3 requests-2.34.2 requests-toolbelt-1.0.0 sniffio-1.3.1 tenacity-9.1.4 urllib3-2.7.0 uuid-utils-0.17.0 websockets-15.0.1 xxhash-3.8.1 zstandard-0.25.0

顺便把openai的支持也安装了,pip3 install -U langchain-openai

bash 复制代码
Installing collected packages: tqdm, regex, jiter, tiktoken, openai, langchain-openai
Successfully installed jiter-0.16.0 langchain-openai-1.3.5 openai-2.45.0 regex-2026.7.10 tiktoken-0.13.0 tqdm-4.68.4

总结

python是否使用自由线程版本可以通过python3 -VV查看,不带free threading的为常规版本,默认python的官方安装包,默认是不会安装自由线程的版本的。

笔者通过这次的示例发现了如何排查安装失败的场景,如何去处理这些问题,分享经验总结。

相关推荐
大模型真好玩2 小时前
LangChain DeepAgents 速通指南(十一)—— DeepAgents Code 记忆与状态管理
人工智能·langchain·agent
lhxcc_fly3 小时前
LangGraph基础知识点
python·langchain·llm·langgraph
BraveWang5 小时前
【LangChain 1.x】05、结构化输出|三种结构定义模式与两种结果获取方式
langchain
俊俊谢6 小时前
从零搭建:本地LangChain Agent调用远程LLaMA-Factory模型服务
langchain·llama
怕浪猫6 小时前
第15章 安全、伦理与合规
langchain·openai·agent
向日的葵00618 小时前
langchain的Tools教程(三)
python·langchain·tools
马里马里奥-1 天前
大模型应用开发笔记04:LangChain 工具(Tool)与中间件(Middleware)详解
笔记·中间件·langchain
常常有1 天前
LangChain 学习记录 03:提示词模板 PromptTemplate 与 ChatPromptTemplate 详解
学习·langchain
大流星1 天前
LangChainJS之Chain链(四)
javascript·langchain