tiktokenのインストールエラー解決方法

スポンサーリンク

Pythonのパッケージインストールにおいて、tiktokenをインストールする際に生じるエラーの解決方法を解説します。

エラー状況

pip install -r requirements.txt

のようにpipコマンドでPythonの依存パッケージをインストールする際、以下のようなエラーが発生しました。

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
  ╰─> [49 lines of output]
      /tmp/pip-build-env-ih5tddum/overlay/lib/python3.12/site-packages/setuptools/config/_apply_pyprojecttoml.py:82: SetuptoolsDeprecationWarning: project.license as a TOML table is deprecated
      !!

              ********************************************************************************
              Please use a simple string containing a SPDX expression for project.license. You can also use project.license-files. (Both options available on setuptools>=77.0.0).

              By 2026-Feb-18, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.

              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
              ********************************************************************************

      !!
        corresp(dist, value, root_dir)
      running bdist_wheel
      running build
      running build_py
      creating build/lib.linux-x86_64-cpython-312/tiktoken
      copying tiktoken/load.py -> build/lib.linux-x86_64-cpython-312/tiktoken
      copying tiktoken/registry.py -> build/lib.linux-x86_64-cpython-312/tiktoken
      copying tiktoken/model.py -> build/lib.linux-x86_64-cpython-312/tiktoken
      copying tiktoken/__init__.py -> build/lib.linux-x86_64-cpython-312/tiktoken
      copying tiktoken/core.py -> build/lib.linux-x86_64-cpython-312/tiktoken
      creating build/lib.linux-x86_64-cpython-312/tiktoken_ext
      copying tiktoken_ext/openai_public.py -> build/lib.linux-x86_64-cpython-312/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.linux-x86_64-cpython-312/tiktoken
      running build_ext
      running build_rust
      error: can't find Rust compiler

原因

tiktokenパッケージのビルドにはRustコンパイラが必要ですが、実行環境にそれがインストールされていないことが原因でした。

解決方法

上記のようにtiktoken をビルドするには Rust が必要なので、以下のどちらかの方法で Rust をインストールします。

方法1. Rustupを使ってインストールする

Rustはrustupというツールによってインストール・管理されています。

以下のコマンドを実行するだけで簡単にRustをインストールすることができます。

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

方法2. パッケージマネージャを使ってインストールする

LinuxのUbuntu / Debian環境の場合、以下のコマンドでRust をインストールできます。

sudo apt update
sudo apt install rustc cargo

これらの方法でRustをインストールすることで、tiktokenのインストールが成功します。

コメント

タイトルとURLをコピーしました