Skip to content

How to set PYTHONPATH for python shell based on project root? #91

Open
@orlandini

Description

@orlandini

Hello,
I am using pyright and I am currently able to detect my (sub)project root by means of a .projectile file in the desired directory.
In this way, pyright finds all my modules as expected.

Now, I would like to start a python shell with the project root directory prepended to my existing PYTHONPATH.

I've found a way to change the working directory of the python interpreter:

(defun my-run-python ()
  (interactive)
  (let ((default-directory (or (projectile-project-root) default-directory)))
    (call-interactively #'run-python)))

However, this is not the behaviour I intended. I just would like to prepend (projectile-project-root) to the PYTHONPATH seen by the python interpreter when called through run-python whenever I am in a project using pyright. Perhaps using lsp-pyright-extra-paths would be useful, but I am not an expert in Lisp.

Best regards and thank you in advance,

Francisco

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions