user1611830
user1611830

Reputation: 4865

Unusual notation - python

It might be a very simple question. I was running a python code, and I got an error message as such :

File "/home/mbenchoufi/brisket/../brisket/views.py", line 11, in <module>
from influence.forms import SearchForm

ImportError: No module named forms

The problem is first that I have indeed a file called views.py in /home/myname/brisket/ but I don''t understand the notation : /home/myname/brisket/../brisket/views.py

Do I have a path config problem and what does this notation means ?

Btw, a really weird thing is that I have a file called forms.py, in the influence folder, and in this file a I have a class called SearchForm... How can the error message can be ?

Upvotes: 2

Views: 123

Answers (2)

David Z
David Z

Reputation: 131800

This is not a Python-specific notation, it's a UNIX filesystem notation. .. in a UNIX path means "back up one directory," so for example, in this case, /home/myname/brisket/.. is equivalent to just /home/myname.

The reason Python displays the filename in this way might be that your sys.path has actually has /home/myname/brisket/.. in it for some reason. It's not a problem, since Python will be able to follow the ..s in the path just fine.

What this error message is telling you is that, while processing the file /home/myname/brisket/../brisket/views.py (which is the same file as /home/myname/brisket/views.py) there is a line of code

from influence.forms import SearchForm

which caused an error. Specifically, it's an ImportError, meaning that the file influence/forms.py wasn't found (or could not be read) by Python's import mechanism. You should check the value of sys.path in your Python program to make sure that the parent directory of influence/ is in the list, and make sure that the file is readable. (Also make sure that influence/__init__.py exists, though I'm not sure that particular problem would cause the error you're seeing.)

Upvotes: 5

sehe
sehe

Reputation: 393934

"/home/myname/brisket/../brisket/views.py"

is equivalent to

"/home/myname/brisket/views.py"

The cause might be an entry in you PYTHONPATH, e.g. like

export PYTHONPATH="$HOME/../brisket:$PYTHONPATH"

http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH

The above approach has the benefit of working for other users, while not requiring an absolute path to /home. Write it like

export PYTHONPATH="/home/brisket:$PYTHONPATH"

to get simpler paths

Upvotes: 2

Related Questions