window环境下,安装pip install tiktoken报错
C:\Users\leifeng1>pip install tiktoken
Collecting tiktoken
Using cached tiktoken-0.3.3.tar.gz (25 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting regex>=2022.1.18 (from tiktoken)
Using cached regex-2023.3.23-cp39-cp39-win32.whl (255 kB)
Requirement already satisfied: requests>=2.26.0 in c:\users\leifeng1\appdata\local\programs\python\python39-32\lib\site-packages (from tiktoken) (2.28.2)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\leifeng1\appdata\local\programs\python\python39-32\lib\site-packages (from requests>=2.26.0->tiktoken) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in c:\users\leifeng1\appdata\local\programs\python\python39-32\lib\site-packages (from requests>=2.26.0->tiktoken) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\leifeng1\appdata\local\programs\python\python39-32\lib\site-packages (from requests>=2.26.0->tiktoken) (1.25.11)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\leifeng1\appdata\local\programs\python\python39-32\lib\site-packages (from requests>=2.26.0->tiktoken) (2022.12.7)
Building wheels for collected packages: tiktoken
Building wheel for tiktoken (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for tiktoken (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [37 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win32-cpython-39
creating build\lib.win32-cpython-39\tiktoken
copying tiktoken\core.py -> build\lib.win32-cpython-39\tiktoken
copying tiktoken\load.py -> build\lib.win32-cpython-39\tiktoken
copying tiktoken\model.py -> build\lib.win32-cpython-39\tiktoken
copying tiktoken\registry.py -> build\lib.win32-cpython-39\tiktoken
copying tiktoken\__init__.py -> build\lib.win32-cpython-39\tiktoken
creating build\lib.win32-cpython-39\tiktoken_ext
copying tiktoken_ext\openai_public.py -> build\lib.win32-cpython-39\tiktoken_ext
running egg_info
writing tiktoken.egg-info\PKG-INFO
writing dependency_links to tiktoken.egg-info\dependency_links.txt
writing requirements to tiktoken.egg-info\requires.txt
writing top-level names to tiktoken.egg-info\top_level.txt
reading manifest file 'tiktoken.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'Makefile'
adding license file 'LICENSE'
writing manifest file 'tiktoken.egg-info\SOURCES.txt'
copying tiktoken\py.typed -> build\lib.win32-cpython-39\tiktoken
running build_ext
running build_rust
error: can't find Rust compiler
If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
To update pip, run:
pip install --upgrade pip
and then retry package installation.
If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for tiktoken
Failed to build tiktoken
ERROR: Could not build wheels for tiktoken, which is required to install pyproject.toml-based projects
根据提示,去装了pyproject.toml,装完之后继续报错,一样的错误,同时也试过装rust,也不行,报错
试试?
pip3 install tiktoken
或者:在命令行中执行
python -m pip install --upgrade pip
命令可以将 pip 更新到最新版。
这个错误不少人遇到,究其原因,就是在安装包的过程中,某些依赖包无法在pip的安装源中找到。根据你提供的信息来看,错误已经提示了can't find Rust compiler,无法找到rust编译器,那么解决方法就是:
先升级你的 pip 和 setuptools。
之后安装setuptools_rust:
pip install setuptools_rust
然后安装rust:
pkg install rust
建议参考这篇文章https://blog.csdn.net/chillging/article/details/108366097
从错误信息来看,安装tiktoken失败的原因是:找不到Rust编译器。
tiktoken这个包依赖Rust语言编写的代码,所以在构建wheel包的时候需要调用Rust编译器。但是在你的环境中似乎没有找到Rust编译器,所以构建失败了。
要解决这个错误,有几种方法:
引用chatGPT作答,根据报错信息,看起来是缺少 Rust 编译器导致的问题,您可以尝试安装 Rust 编译器,并将其添加到 PATH 环境变量中,方法如下:
1.首先访问 https://rustup.rs/%EF%BC%8C%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85 Rust 编译器。
2.安装完成后,将其添加到 PATH 环境变量中。在 Windows 上,您可以按 Win+R 组合键打开运行对话框,输入 sysdm.cpl 并按 Enter 键打开系统属性对话框,在高级选项卡下的环境变量中,找到 Path 变量,将 Rust 的 bin 目录添加到其中即可,如:C:\Users\username.cargo\bin。
3.最后重新打开命令行窗口,执行 pip install tiktoken 命令,看是否能够成功安装。
如果问题仍然存在,请确保您的 pip 已经升级到最新版本,可以使用以下命令进行升级:
pip install --upgrade pip
希望这些步骤可以帮助您解决问题。
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
这个错误是因为python库tiktoken需要依赖Rust编译器来构建其静态链接库,但是你的系统中没有安装Rust编译器,所以会出现上述错误。
如果你想要解决这个问题,可以按照以下步骤:
你可以从Rust官方网站上下载安装包并安装Rust编译器( https://www.rust-lang.org/tools/install )。如果你是Windows系统,可以使用Rustup,它可以安装Rust编译器以及管理你的Rust环境。
检查Rust编译器是否已经被添加到系统PATH变量中,可以打开终端,运行以下命令:
rustc --version
如果你看到一个类似于以下输出的版本信息,则说明你已经成功安装了Rust编译器:
```rustc 1.58.0