Python安装langchain卡住怎么办?排查pip install langchain失败原因及解决方法

 更新时间:2026年07月15日 09:58:11   作者:fenglllle  
在Python中安装langchain时遇到pip卡住、源下载慢或自由线程版本不兼容等问题?本文分享从清华源、阿里源切换、查看Python版本到成功安装langchain和langchain-openai的排查心得,帮你快速绕过orjson不支持freethreading的坑,顺利推进项目

前言

最近在做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
  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

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

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

切换后安装成功

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

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的官方安装包,默认是不会安装自由线程的版本的。

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • python获取指定时间段内特定规律的日期列表

    python获取指定时间段内特定规律的日期列表

    这篇文章主要介绍了python获取指定时间段内特定规律的日期列表,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-04-04
  • 基于Python的一个自动录入表格的小程序

    基于Python的一个自动录入表格的小程序

    这篇文章主要介绍了基于Python的一个自动录入表格的小程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-08-08
  • Python的条件控制 if 语句详解

    Python的条件控制 if 语句详解

    Python的 if 语句用来「控制代码」的执行,「判断条件成立」时执行一段代码,判断条件「不成立」时执行另一段代码,本文就给大家详细讲讲Python的条件控制 if 语句,需要的朋友可以参考下
    2023-08-08
  • python实现简单的socket server实例

    python实现简单的socket server实例

    这篇文章主要介绍了python实现简单的socket server的方法,实例分析了Python中socket的操作技巧,非常具有实用价值,需要的朋友可以参考下
    2015-04-04
  • 举例简单讲解Python中的数据存储模块shelve的用法

    举例简单讲解Python中的数据存储模块shelve的用法

    这篇文章主要介绍了举例简单讲解Python中的数据存储模块shelve的用法,shelveshelve模块与pickle模块的功能相近,比pickle用起来更为简单,需要的朋友可以参考下
    2016-03-03
  • 基于Keras 循环训练模型跑数据时内存泄漏的解决方式

    基于Keras 循环训练模型跑数据时内存泄漏的解决方式

    这篇文章主要介绍了基于Keras 循环训练模型跑数据时内存泄漏的解决方式,具有很好的参考价值,希望对大家有所帮助。一起跟随想过来看看吧
    2020-06-06
  • pytorch保存和加载模型的方法及如何load部分参数

    pytorch保存和加载模型的方法及如何load部分参数

    本文总结了pytorch中保存和加载模型的方法,以及在保存的模型文件与新定义的模型的参数不一一对应时,我们该如何加载模型参数,对pytorch保存和加载模型相关知识感兴趣的朋友一起看看吧
    2024-03-03
  • Python使用Mechanize模块编写爬虫的要点解析

    Python使用Mechanize模块编写爬虫的要点解析

    这篇文章主要介绍了Python使用Mechanize模块编写爬虫的要点解析,作者还讲解了Mechanize程序占用内存过高问题的相关解决方法,需要的朋友可以参考下
    2016-03-03
  • 使用python AI快速比对两张人脸图像及遇到的坑

    使用python AI快速比对两张人脸图像及遇到的坑

    这篇文章主要介绍了如何使用python AI快速比对两张人脸图像?实现过程比较简单,但是第三方python依赖的安装过程较为曲折,下面是通过实践对比总结出来的能够支持的几个版本,避免大家踩坑,需要的朋友可以参考下
    2023-02-02
  • Python笔记之facade模式

    Python笔记之facade模式

    这篇文章主要为大家详细介绍了Python笔记之facade模式,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-11-11

最新评论