Note: This was initially posted on StackOverflow a few months back and hasn't received an answer, but I'm reposting it since the Emacs StackExchange is now available.
I'm in the process of converting over from using Eclipse to Emacs 24.3 and Elpy 1.7.50 for my Python development. However, I'm running into a roadblock in getting Elpy to recognize my project. Based on my understanding of the way elpy should work from the documentation, if I set a project root folder, that folder should be included in the sys.path
to search for modules. This is not happening.
The Elpy Documentation doesn't seem to have any answers to my particular conundrum, nor can I find a basic tutorial that walks me through creating my first Elpy project to break it down and show me what I'm doing wrong.
In the shell, I first create the virtual environment virtualenv
using
mkvirtualenv
from virtualenvwrapper
. Then I create the following
folder/file structure within the virtualenv folder:
virtualenv/
└─ my_project/
├─ src/
│ └─ my_project/
│ ├─ __init__.py
│ └─ foo.py
└─ test/
The contents of foo.py
are:
class foo(object):
pass
if __name__ == '__main__':
pass
Next, I connect to an already-running instance of Emacs server using the Emacs client. Within Emacs, I enter:
M-x pyvenv-workon virtualenv
Emacs does show [my_project]
in the mode line. Next, I enter:
M-x elpy-set-project-root ~/Projects/my_project/src
Then, I type C-cC-f to search the project for a file, and I get:
C-c C-f is undefined
So, I type:
M-x elpy-find-file
and I get:
No project root found
If I create the file test/test_foo.py
with the following code:
from my_project import foo
if __name__ == '__main__':
pass
and then run it using C-cC-c, I get:
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/doug/Projects/my_project/src/test/test_foo.py", line 1, in <module>
from my_project import foo
ImportError: No module named 'my_project'
>>>
__init__.py
(the topmost one), not thesrc
.