Skip to content

Commit

Permalink
Explain PYTHONPATH setup in build instructions. (#14834)
Browse files Browse the repository at this point in the history
As requested [here on
Discord](https://discord.com/channels/689900678990135345/706175572920762449/1144535632039915564).

Also
* Suggest using `help(iree.[compiler|runtime])` to show that import was
successful, rather than just `import`, which has no output
* Write out `.env.ps1` for PowerShell usage on Windows
  • Loading branch information
ScottTodd authored Nov 9, 2023
1 parent b55da2b commit 2fe00a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,11 @@ if(IREE_BUILD_PYTHON_BINDINGS)
set(_PYTHONPATH_ENV "PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n")
file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env" CONTENT "${_PYTHONPATH_ENV}")
# Similarly, write out .env.bat for Windows.
# Similarly, write out .env.bat and .env.ps1 for Windows.
set(_PYTHONPATH_ENV_BAT "set PYTHONPATH=$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>\n")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.bat" CONTENT "${_PYTHONPATH_ENV_BAT}")
set(_PYTHONPATH_ENV_PS1 "$env:PYTHONPATH = '$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/compiler/bindings/python;${CMAKE_CURRENT_BINARY_DIR}/runtime/bindings/python>'\n")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env.ps1" CONTENT "${_PYTHONPATH_ENV_PS1}")
endif()

if(IREE_BUILD_BINDINGS_TFLITE)
Expand Down
23 changes: 16 additions & 7 deletions docs/website/docs/building-from-source/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,33 @@ Extend your `PYTHONPATH` with IREE's `bindings/python` paths and try importing:

``` shell
source ../iree-build/.env && export PYTHONPATH
python -c "import iree.compiler"
python -c "import iree.runtime"
# The 'PYTHONPATH' environment variable should now contain
# iree-build/compiler/bindings/python;iree-build/runtime/bindings/python

python -c "import iree.compiler; help(iree.compiler)"
python -c "import iree.runtime; help(iree.runtime)"
```

=== ":fontawesome-brands-apple: macOS"

``` shell
source ../iree-build/.env && export PYTHONPATH
python -c "import iree.compiler"
python -c "import iree.runtime"
# The 'PYTHONPATH' environment variable should now contain
# iree-build/compiler/bindings/python;iree-build/runtime/bindings/python

python -c "import iree.compiler; help(iree.compiler)"
python -c "import iree.runtime; help(iree.runtime)"
```

=== ":fontawesome-brands-windows: Windows"

``` powershell
../iree-build/.env.bat
python -c "import iree.compiler"
python -c "import iree.runtime"
..\iree-build\.env.ps1 # or ..\iree-build\.env.bat
# The 'PYTHONPATH' environment variable should now contain
# iree-build/compiler/bindings/python;iree-build/runtime/bindings/python

python -c "import iree.compiler; help(iree.compiler)"
python -c "import iree.runtime; help(iree.runtime)"
```

Using IREE's ML framework importers requires a few extra steps:
Expand Down

0 comments on commit 2fe00a5

Please sign in to comment.