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:

└─ my_project/
   ├─ src/
   │  └─ my_project/
   │     ├─ __init__.py
   │     └─ foo.py
   └─ test/

The contents of foo.py are:

class foo(object):

if __name__ == '__main__':

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__':

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'
  • I think that project root is the directory containing __init__.py (the topmost one), not the src.
    – wvxvw
    Commented Jun 22, 2015 at 17:18
  • @wvxvw - I believe that this is one of the items I ticked off as I was troubleshooting this issue, but I can't remember, so I will try that again. Thanks.
    – Deacon
    Commented Jun 22, 2015 at 19:21
  • Another guess: iirc Ropes creates a special project file, where it stores project settings. I think elpy can use Ropes or Jedy back-end, Ropes would be the default one. I'm not sure it should create a Ropes project, but if it does, can you look into it and see if there's some relevant info there?
    – wvxvw
    Commented Jun 22, 2015 at 20:11

1 Answer 1


Elpy knows of two "roots" for your directory, the "project root" and the "library root". The project root is used for file searches and similar, while the library root is the directory added to sys.path.

In your example, my_project/ should be the project root, while my_project/src/ should be the library root. You can verify this using M-: (elpy-project-root) and M-: (elpy-library-root) in a Python file.

But you opened a file in test/. For files in there, Elpy will find my_project/test/ as the library root, as it does not know about src/.

Your best option is to use virtualenvwrapper's add2virtualenv tool to add your project – my_project/src/ – to your virtauelvn's library path.

Hope this helps :-)

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.