Python search path - python can't find my modules

18,223

Solution 1

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

Solution 2

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?

Share:
18,223
Marcin
Author by

Marcin

If you're thinking about kicking off a data project, or need to upgrade your data systems let me know. I'm an experienced data engineer, with partners and subcontractors available to take on any project you need.

Updated on June 04, 2022

Comments

  • Marcin
    Marcin almost 2 years

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