Deacon
Deacon

Reputation: 3803

Emacs 24 with Elpy 1.7.50 does not recognize Python Project

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

Upvotes: 1

Views: 624

Answers (2)

serv-inc
serv-inc

Reputation: 38177

Have you tried installing projectile? It solved similar problems at https://github.com/jorgenschaefer/elpy/issues/957 and Set Python project root in Emacs?.

You can install projectile via emacs's package manager:

M-x package-list-packages, select projectile (shorthands: i x to mark as install, and execute).

Upvotes: 1

Alioth
Alioth

Reputation: 603

Could you review ~/.emacs.d/elpa/find-file-in-project-3.3/find-file-in-project.el please. There are several strings about project definition criteria and I've found:

(require 'cl)
(defvar ffip-project-file ".git"
  "The file that should be used to define a project root.

I've tested M-x elpy-set-project-root and M-x elpy-find-file inside my git repo and it works (with several quirks:-).

In other words: feel free to customize it by yourself.

Upvotes: 0

Related Questions