Skip to content

Commit 1b94055

Browse files
JiwaniZakirclaude
andauthored
Fix #18714: [Docs] python -c "import tvm; print(tvm.file)" fail (#19407)
Closes #18714 ## Before Following the source installation docs, users who set up `PYTHONPATH` with only `$TVM_HOME/python` would hit an `importlib.metadata.PackageNotFoundError: apache-tvm-ffi` when running `python -c "import tvm"`. This happened because `tvm_ffi/__init__.py` calls `libinfo.load_lib_ctypes("apache-tvm-ffi", ...)`, which uses `importlib.metadata.distribution("apache-tvm-ffi")` to locate the shared library — a lookup that requires the `apache-tvm-ffi` package to be registered in the Python environment, not just present on `PYTHONPATH`. ## After The `tvm-ffi` package at `3rdparty/tvm-ffi` is installed into the active Python environment via `pip install` before any `import tvm` is attempted. The `PYTHONPATH` export in `docs/install/from_source.rst` is also updated to include `$TVM_HOME/3rdparty/tvm-ffi/python` alongside `$TVM_HOME/python`, matching the environment layout expected by the FFI loader. ## Changes - **`docs/install/from_source.rst` (line ~165–166):** Added `pip install $TVM_HOME/3rdparty/tvm-ffi` step before the `export PYTHONPATH` line in the "set environment variable" path. Updated the `PYTHONPATH` export to append `$TVM_HOME/3rdparty/tvm-ffi/python`, ensuring both the package metadata (from the pip install) and the Python sources are resolvable. ## Testing Manual verification on a from-source build with the updated instructions: ``` $ pip install $TVM_HOME/3rdparty/tvm-ffi $ export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/3rdparty/tvm-ffi/python:$PYTHONPATH $ python -c "import tvm; print(tvm.__file__)" /path-to-tvm/python/tvm/__init__.py ``` No `PackageNotFoundError` is raised; `importlib.metadata.distribution("apache-tvm-ffi")` resolves correctly after the pip install step. --- *This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.* Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 14751b3 commit 1b94055

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

docs/install/from_source.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ Leaving the build environment ``tvm-build-venv``, there are two ways to install
163163
.. code-block:: bash
164164
165165
export TVM_HOME=/path-to-tvm
166-
export PYTHONPATH=$TVM_HOME/python:$PYTHONPATH
166+
pip install $TVM_HOME/3rdparty/tvm-ffi
167+
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/3rdparty/tvm-ffi/python:$PYTHONPATH
167168
168169
- Install via pip local project
169170

0 commit comments

Comments
 (0)