Skip to content

from executorch.exir import CaptureConfig fails with ExecuTorch pip installed in editable mode #9558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
swolchok opened this issue Mar 24, 2025 · 4 comments · Fixed by #9818
Assignees
Labels
module: dev infra Issues related to developer infrastructure (other than CI, which is module: ci)

Comments

@swolchok
Copy link
Contributor

🐛 Describe the bug

python -c 'from executorch.exir import CaptureConfig' works with ExecuTorch installed via ./install_executorch.sh, but fails with ExecuTorch installed by pip install -e .:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from executorch.exir import CaptureConfig
ImportError: cannot import name 'CaptureConfig' from 'executorch.exir' (unknown location)

Versions

main

@swolchok swolchok added the module: dev infra Issues related to developer infrastructure (other than CI, which is module: ci) label Mar 24, 2025
@JacobSzwejbka
Copy link
Contributor

@larryliu0820 @GregoryComer have you guys worked on the pip build before?

@larryliu0820
Copy link
Contributor

According to https://stackoverflow.com/questions/64838393/package-dir-in-setup-py-not-working-as-expected our current pattern cannot be supported in editable mode.

Basically our file structure stopped us from doing from executorch.exir import CaptureConfig because editable mode can't take __init__.py under exir/. Like you can do from executorch.backends import apple because there's no __init__.py under backends/.

I think this can't be fixed until we have an executorch/ like mentioned in #8699

@larryliu0820 larryliu0820 moved this from To triage to Backlog in ExecuTorch Core Mar 25, 2025
@swolchok
Copy link
Contributor Author

swolchok commented Mar 25, 2025

@larryliu0820 re: prioritization as backlog, note that this blocks building ExecuTorch through CMake with the pip installed in editable mode.

@larryliu0820
Copy link
Contributor

@swolchok yeah to work around I think you can do from executorch.exir.capture import CaptureConfig

larryliu0820 added a commit that referenced this issue Apr 1, 2025
…l module such as exir

Summary:

Fixes #9558.

The `src/executorch/exir` file exists primarily due to the limitations of `pip install` in editable mode. Specifically, `pip install -e .` does not recognize `<executorch root>/exir` (or any root level directory with a `__init__.py`) as a valid package module because of the presence of `<executorch root>/exir/__init__.py`. See the following GitHub issue for details: [Issue #9558](#9558).

To work around this limitation, a symlink is used. With this symlink and this package entry in `pyproject.toml`:

```toml
[tool.setuptools.package-dir]
...
"executorch" = "src/executorch"
```
We are telling `pip install -e .` to treat `src/executorch` as the root of the `executorch` package and hence mapping `executorch.exir` to `src/executorch/exir`.

This allows us to perform `pip install -e .` successfully and enables the execution of the following command:

```bash
python -c "from executorch.exir import CaptureConfig"
```

Test Plan:

```bash
./install_executorch.sh --pybind --editable
python -c "from executorch.exir import CaptureConfig"
```

Reviewers:

Subscribers:

Tasks:

Tags:
@github-project-automation github-project-automation bot moved this from Backlog to Done in ExecuTorch Core Apr 2, 2025
kirklandsign pushed a commit that referenced this issue Apr 11, 2025
…l module such as exir (#9818)

Summary:

Fixes #9558.

The `src/executorch/exir` file exists primarily due to the limitations
of `pip install` in editable mode. Specifically, `pip install -e .` does
not recognize `<executorch root>/exir` (or any root level directory with
a `__init__.py`) as a valid package module because of the presence of
`<executorch root>/exir/__init__.py`. See the following GitHub issue for
details: [Issue
#9558](#9558).

To work around this limitation, a symlink is used. With this symlink and
this package entry in `pyproject.toml`:

```toml
[tool.setuptools.package-dir]
# ...
"executorch" = "src/executorch"
```
We are telling `pip install -e .` to treat `src/executorch` as the root
of the `executorch` package and hence mapping `executorch.exir` to
`src/executorch/exir`. This effectively gets `exir` out from the root
level package.

This allows us to perform `pip install -e .` successfully and enables
the execution of the following command:

```bash
python -c "from executorch.exir import CaptureConfig"
```

Test Plan:

```bash
./install_executorch.sh --pybind --editable
python -c "from executorch.exir import CaptureConfig"
```

Reviewers:

Subscribers:

Tasks:

Tags:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: dev infra Issues related to developer infrastructure (other than CI, which is module: ci)
Projects
Status: Done
3 participants