Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 356
Marcin Avatar asked Jan 17 '26 23:01

Marcin


2 Answers

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

like image 192
David Wolever Avatar answered Jan 19 '26 14:01

David Wolever


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?

like image 42
Chris Phillips Avatar answered Jan 19 '26 15:01

Chris Phillips



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!