Skip to content

Fix #18714: [Docs] python -c "import tvm; print(tvm.file)" fail#19407

Merged
tlopex merged 1 commit intoapache:mainfrom
JiwaniZakir:fix/18714-docs-python-c-import-tvm-print-tvm-file
Apr 15, 2026
Merged

Fix #18714: [Docs] python -c "import tvm; print(tvm.file)" fail#19407
tlopex merged 1 commit intoapache:mainfrom
JiwaniZakir:fix/18714-docs-python-c-import-tvm-print-tvm-file

Conversation

@JiwaniZakir
Copy link
Copy Markdown
Contributor

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>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the TVM source installation documentation to include the installation of the tvm-ffi dependency and its addition to the PYTHONPATH. The reviewer suggested using an editable installation for tvm-ffi to ensure the package remains synchronized with the source tree and to avoid redundant entries in the PYTHONPATH.

Comment on lines +166 to +167
pip install $TVM_HOME/3rdparty/tvm-ffi
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/3rdparty/tvm-ffi/python:$PYTHONPATH
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using an editable install (pip install -e) for tvm-ffi is a more robust approach for a source-based installation. It registers the necessary package metadata to resolve the PackageNotFoundError while keeping the package linked to the source directory. This ensures that tvm-ffi stays in sync with your source tree (e.g., after a git pull) and removes the need to manually add its path to PYTHONPATH. Having the same package in both site-packages and PYTHONPATH is redundant and can lead to import conflicts or version mismatches.

Suggested change
pip install $TVM_HOME/3rdparty/tvm-ffi
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/3rdparty/tvm-ffi/python:$PYTHONPATH
pip install -e $TVM_HOME/3rdparty/tvm-ffi
export PYTHONPATH=$TVM_HOME/python:$PYTHONPATH

@tlopex tlopex merged commit 1b94055 into apache:main Apr 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants