For some reason, emacs does not seem capable of evaluating absolute imports for any python project I run. Here is my project layout:
├── loxy
│ ├── errors.py
│ ├── __init__.py
│ ├── loxy.py
│ ├── scanner.py
│ ├── token_.py
│ └── token_type.py
└── setup.py
When I enter an inferior python shell, I am incapable of importing any of my project's modules that are declared using absolute or relative imports. E.g.
from X.Y import y
from .Y import y
Marking the above and running python-shell-send-region
, or just sending the whole buffer, results in a ModuleNotFoundError
for any import that does either of the above.
The only format that is unaffected is:
from Y import y
But this is incompatible with packaging with pip, which I will often do to test the package as a whole as a program via local installs, pip install -e .
from the root of the package. Pip will work just fine with either relative or absolute imports, but emacs' inferior repl works with neither currently. This puts me at an impasse.
Any ideas?
Extra details:
Auto completion works just fine with my setup. Virtualenvs are detected fine with pyenv-mode
and imports work with any of the styles I listed above. This is probably a path related error, but I am not sure how/why it is happening.
Update
Answered my own question after wasting a lot of hours trying to fix my workflow. Not proud of it but hope it might help someone else better understand how python works from within emacs.
sys.path
. See what's there, and this may give you a hint about why things you are looking for not there. As an aside: did you install your project into your virtual environment, or did you, perhaps, modifyPYTHONPATH
to point at your project? Why do you think Python should know where your project is?