jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 261 forks source link

Elpy-shell always evaluate at git repo root #1815

Open shenzh1206 opened 4 years ago

shenzh1206 commented 4 years ago

Summary

I ran into error messages stating that my custom python module in the same directory is not found when evaluating in elpy-shell (ctrl-c ctrl-c). when directly evaluating the file in terminal, everything works. I added the following code to my file:

import os print(os.getcwd())

it always prints my git repo root. I have tried to set use project root to nil and set elpy-shell start dir to current dir. but it still stuck at git repo root dir. I also tried to explicit set project root dir to current dir, it still prints the git repo root dir.

My configuration

I'm using Linux debian 10

Result of (elpy-config)

Elpy Configuration

Emacs.............: 26.1
Elpy..............: 1.34.0
Virtualenv........: None
Interactive Python: python 2.7.16 (/usr/bin/python)
RPC virtualenv....: rpc-venv (/home/dshen/.emacs.d/elpy/rpc-venv)
 Python...........: python 2.7.16 (/home/dshen/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.17.1
 Rope.............: 0.17.0
 Autopep8.........: 1.5.3
 Yapf.............: 0.30.0
 Black............: Not found (19.10b0 available)
Syntax checker....: flake8 (/home/dshen/.local/bin/flake8)

Warnings

You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.

The black package is not available. Commands using this will not work.

[Install black]

Options

`Raised' text indicates buttons; type RET or click mouse-1 on a button
to invoke its action.  Invoke [+] to expand a group, and [-] to
collapse an expanded group.  Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.

[+]-- Group Elpy
[+]-- Group Python
[+]-- Group Virtual Environments (Pyvenv)
[+]-- Group Completion (Company)
[+]-- Group Call Signatures (ElDoc)
[+]-- Group Inline Errors (Flymake)
[+]-- Group Code folding (hideshow)
[+]-- Group Snippets (YASnippet)
[+]-- Group Directory Grep (rgrep)
[+]-- Group Search as You Type (ido)
[+]-- Group Django extension
[+]-- Group Autodoc extension

Elpy configuration in my init.el

(elpy-enable)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode)
(pyenv-mode)
(setq elpy-shell-use-project-root nil)
(setq python-shell-interpreter "python3")
galaunay commented 3 years ago

elpy-shell-use-project-root is an obsolete variable as of Elpy 1.33. (setq elpy-shell-starting-directory 'current-directory) should work, but it requires you to restart the python interpreter afterwards (with C-c C-k followed by C-c C-z). Have you done that ?

note: I have updated the documentation to make that last point clear.