You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cygwin环境下安装Python bcrypt失败,无法定位Python解释器

在Cygwin中安装bcrypt时出现Python解释器找不到的问题

我尝试在Cygwin中安装paramiko,它的构建依赖之一是bcrypt。已安装rustc,确认所有构建支持库配置完成,pip也更新到了最新版本:

$ pip --version
pip 22.2.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

执行pip install bcrypt时出现以下错误:

error: failed to run custom build command for `pyo3-build-config v0.15.2`

Caused by:
  process didn't exit successfully: `C:\Cygwin64\tmp\pip-install-19d9dusl\bcrypt_117761e212a240d8804ceae0beeb39c1\src\_bcrypt\target\release\build\pyo3-build-config-2ef06b5f5d02e46b\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-env-changed=PYO3_CONFIG_FILE
  cargo:rerun-if-env-changed=PYO3_NO_PYTHON
  cargo:rerun-if-env-changed=PYO3_PYTHON

  --- stderr
  error: failed to run the Python interpreter at /usr/bin/python.exe: The system cannot find the path specified. (os error 3)
warning: build failed, waiting for other jobs to finish...
cargo rustc --lib --message-format=json-render-diagnostics --manifest-path src/_bcrypt/Cargo.toml --release -v --features pyo3/abi3-py36 pyo3/extension-module -- --crate-type cdylib

    =============================DEBUG ASSISTANCE=============================
    If you are seeing a compilation error please try the following steps to
    successfully install bcrypt:
    1) Upgrade to the latest pip and try again. This will fix errors for most
       users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
    2) Ensure you have a recent Rust toolchain installed. bcrypt requires
       rustc >= 1.56.0.

    Python: 3.8.12
    platform: CYGWIN_NT-10.0-19044-3.3.5-341.x86_64-x86_64-64bit-WindowsPE
    pip: n/a
    setuptools: 65.3.0
    setuptools_rust: 1.5.1
    rustc: 1.63.0 (4b91a6ea7 2022-08-08)
    =============================DEBUG ASSISTANCE=============================

error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path src/_bcrypt/Cargo.toml --release -v --features 'pyo3/abi3-py36 pyo3/extension-module' -- --crate-type cdylib` failed with code 101
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.   ERROR: Failed building wheel for bcrypt Failed to build bcrypt ERROR: Could not build wheels for bcrypt, which is required to install pyproject.toml-based projects

我已经确认Python解释器确实在/usr/bin/python.exe路径下:

$ ls /usr/bin/python*
/usr/bin/python.exe        /usr/bin/python2.7.exe   /usr/bin/python3.8-config
/usr/bin/python2-config    /usr/bin/python3         /usr/bin/python3.8.exe
/usr/bin/python2.7-config  /usr/bin/python3-config

问题:为什么程序找不到已存在的Python解释器?bcrypt无法构建安装的原因是什么?


问题原因

Cygwin的类Unix路径在Windows原生进程中无法直接识别——pyo3的构建脚本是以Windows原生程序身份运行的,它没法解析Cygwin格式的/usr/bin/python.exe路径,需要转换成Windows绝对路径格式(比如C:\Cygwin64\usr\bin\python.exe)。

解决步骤

  • 指定PYO3_PYTHON环境变量
    执行安装命令前,先设置环境变量指向Python解释器的Windows绝对路径:

    export PYO3_PYTHON=C:/Cygwin64/usr/bin/python3.8.exe
    

    若你安装的是32位Cygwin,路径改为C:/Cygwin/usr/bin/python3.8.exe即可。

  • 直接用对应Python版本执行pip
    避免使用通用pip命令,直接调用目标Python版本的pip执行安装:

    python3.8 -m pip install bcrypt
    

    这种方式下pyo3会直接关联当前运行的Python解释器,无需手动解析路径。

  • 安装Python开发包
    打开Cygwin安装程序,搜索并安装python38-devel包(对应你的Python3.8版本),确保构建时能获取到必要的头文件和库。

  • 尝试预编译wheel包
    如果上述方法仍无效,可以下载匹配你Python版本和Cygwin架构的bcrypt预编译wheel包,直接执行本地安装:

    pip install /path/to/bcrypt-xxx-cygwin_xxx.whl
    

内容的提问来源于stack exchange,提问作者rr0711

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 09:24:27