0

I use elpy and I am not able to use relative paths to access files because the PYTHONPATH doesn't include the directory I'm in by default. I may have set it up wrong in elpy-config. Here are my paths by default after using pprint.pprint(sys.path):

['',
 '/usr/lib/python310.zip',
 '/usr/lib/python3.10',
 '/usr/lib/python3.10/lib-dynload',
 '/home/steve/.virtualenvs/venv/lib/python3.10/site-packages',
 '/home/steve/Python/']

I was adding the path every project using os.chdir() but this didn't work for modules so I have been manually appending the path that I'm working in every new project I start by using sys.path.append() and this works fine. How can I have the current directory I'm in added to the path's without having to append it every time?

Emacs.............: 27.1
Elpy..............: 1.35.0
Virtualenv........: venv (/home/steve/.virtualenvs/venv/)
Interactive Python: python3 3.10.4 (/home/steve/.virtualenvs/venv/bin/python3)
RPC virtualenv....: rpc-venv (/home/steve/.emacs.d/.local/etc/elpy/rpc-venv)
 Python...........: python 3.10.4 (/home/steve/.emacs.d/.local/etc/elpy/rpc-venv/bin/python)
 Jedi.............: 0.18.1
 Autopep8.........: 1.6.0
 Yapf.............: 0.32.0
 Black............: 22.3.0
Syntax checker....: flake8 (/home/steve/.virtualenvs/venv/bin/flake8)
2
  • I am not familiar with elpy, but using PYTHONPATH is quite out of fashion these days. Almost everyone I know uses a tool like pipenv or poetry to run their project in a "virtual environment", and I know that there are Emacs packages to support that style of work.
    – q.undertow
    Jun 18, 2022 at 3:28
  • Adding to the previous comment, check out the pyvenv emacs package.
    – Jeremy
    Jun 19, 2022 at 7:53

1 Answer 1

0

I deleted __pycache__ and .mypycache from a parent directory, now my path is functioning as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.