sandialabs / pyttb

Python Tensor Toolbox
https://pyttb.readthedocs.io
BSD 2-Clause "Simplified" License
25 stars 13 forks source link

Issues with editable install (PEP660) #295

Closed ghbrown closed 5 months ago

ghbrown commented 6 months ago

While trying to fork and edit pyttb, I faced errors manifesting as pyttb importing modules/classes/functions in a manner inconsistent with __init__.py.

Ultimately, I believe this is due to issues with pip and/or setuptools as they add support for PEP660 for editable installs of projects using pyproject.toml.

Consider the following code, which uses pyttb in accordance with the init file:

import numpy as np
import pyttb as ttb

X = np.random.uniform(size=(3,3,3))
X = ttb.tensor(X)

M1 = ttb.cp_als(X,3)

This code errors with X = ttb.tensor(X) AttributeError: module 'pyttb' has no attribute 'tensor' if installing pyttb via:

pip install -e ".[dev,doc]"

In particular, it seems that this happens because the pyttb/build/__editable__.pyytb<some more stuff> is not being included in PYTHONPATH, which may be an issue to report upstream to pip or setuptools.

(Workaround) The code runs successfully if installing via:

pip install -e ".[dev,doc]" --config-settings editable_mode=strict

Eventually, I believe a future version of pip and/or setuptools will make this issue irrelevant, but in the meantime here is the workaround. It also seems plausible pyproject.toml could be edited to made more robust to these transitional issues.

System info:

Relevant links:

ghbrown commented 5 months ago

I know nothing changed on your side, but this seems resolved now. The sample code runs successfully after installing via the first (standard) approach.

Not sure if I had some sort of bug in my setup before, or if it has to do with now being on setuptools 70.0.0.