Marcin
Marcin

Reputation: 49846

Python search path - python can't find my modules

I'm trying to run a script from the commandline, and python is having absolutely none of it:

[graffias:~/testing.tustincommercial.com]$ export PYTHONPATH=`pwd`:$PYTHONPATH                                          
[graffias:~/testing.tustincommercial.com]$  python -c 'import oneclickcos.mainapp; mainapp.mail.worker_loop()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named oneclickcos.mainapp
[graffias:~/testing.tustincommercial.com]$ python
Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import oneclickcos
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named oneclickcos
>>>
[graffias:~/testing.tustincommercial.com]$ ls ./oneclickcos/mainapp/mail.py
./oneclickcos/mainapp/mail.py
[graffias:~/testing.tustincommercial.com]$

Any ideas?

Note for the unwary: The command above should be $python -c 'import oneclickcos.mainapp.mail; oneclickcos.mainapp.mail.worker_loop()' (another valid variant).

Upvotes: 2

Views: 18243

Answers (2)

Chris Phillips
Chris Phillips

Reputation: 12387

In order to import from folders like that, they have to be setup as packages. Do oneclickcos and mainapp have __init__.py files in them?

Upvotes: 3

David Wolever
David Wolever

Reputation: 154504

Do you have a __init__.py in oneclickcos/ and in oneclickcos/mainapp/? If not, put one in and try again — that could cause the problem you're seeing.

For more, see http://docs.python.org/tutorial/modules.html

Upvotes: 6

Related Questions