Skip to content

Commit

Permalink
Merge pull request trueagi-io#754 from trueagi-io/repl-python-env-tro…
Browse files Browse the repository at this point in the history
…ubleshooting

Add instruction on troubleshooting REPL under Python virtual env
  • Loading branch information
vsbogd authored Jul 26, 2024
2 parents 2f7a122 + e2fbd1f commit 3d63708
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ cargo run --features python --bin metta-repl
```
You can also find executable at `./target/debug/metta-repl`.

Running the REPL with Python support in a Python virtual environment like PyEnv or Conda requires additional configuration. See [troubleshooting](#rust-repl-cannot-load-python-library)

### Logger

You can enable logging by prefixing the MeTTa command line by
Expand Down Expand Up @@ -270,6 +272,40 @@ ModuleNotFoundError: No module named 'hyperonpy'
Please ensure you have installed the Python module, see
[Running Python and MeTTa examples](#running-python-and-metta-examples).

### Rust REPL cannot load Python library

The REPL needs a path to the libpython library in the current environment. This can be done one of two ways:

#### On Linux

##### Use `patchelf` on resulting REPL binary to link it with `libpython.so`
```
ldd target/debug/metta-repl | grep libpython ; to find <libpython-name>
patchelf --replace-needed <libpython-name> <path-to-libpython-in-virtual-env> target/debug/metta-repl
```
This must be redone each time the repl is rebuilt, e.g. with `cargo build`.

##### Set the `LD_LIBRARY_PATH` environment variable prior to launching `metta-repl`
```
export LD_LIBRARY_PATH=<path-to-libpython-directory-in-virtual-env>
```

#### On Mac OS
##### Use `install_name_tool` to change the REPL binary's link path for `libpython`
```
otool -L target/debug/metta-repl | grep libpython ; to find <libpython-name>
install_name_tool -change <libpython-name> <path-to-libpython-in-virtual-env> target/debug/metta-repl
```
This must be redone each time the repl is rebuilt, e.g. with `cargo build`.

##### Set the `DYLD_FALLBACK_LIBRARY_PATH` environment variable prior to launching `metta-repl`
```
export DYLD_FALLBACK_LIBRARY_PATH=<path-to-libpython-directory-in-virtual-env>
```
This can be done in your `~/.bashrc` file if you don't want to do it each time you launch the REPL.

For more information about linking `libpython`, see [#432](https://github.com/trueagi-io/hyperon-experimental/issues/432).

# Development

## Structure of the codebase
Expand Down

0 comments on commit 3d63708

Please sign in to comment.