4

Here is my relevant directory structure (Windows 7, Python 2.7, virtualenv)

-userProf
-   -   manage.py
    -   -UserProfile
            -   sampleapp_db
            -   urls.py
            -   views.py
            -   wsgi.py
            -   __init__.py
            -   
            -libs
            -   -   __init__.py
            -   -allauth
            -       -   app_settings.py
            -       -   models.py
            -       -   tests.py
            -       -   urls.py
            -       -   utils.py
            -       -   __init__.py
            -       -   
            -       -account
            -       -   -   admin.py
            -       -   -   context_processors.py
            -       -   -   models.py
            -       -   -   urls.py
            -       -   -   __init__.py
            -       -socialaccount
            -       -   -   admin.py
            -       -   -   context_processors.py
            -       -   -   models.py
            -       -   -   urls.py
            -       -   -   views.py
            -       -   -   __init__.py
            -       -   -   
            -       -templates
            -           -account
            -           -   -   base.html
            -           -   -   email.html
            -settings
            -       base_settings.py
            -       dev.py
            -       __init__.py
            -       
            -static
                -css

I get the following error when I try to run this django app Error: No module named account

I have read other posts on SO that refer to the syspath being the issue or that the appname matches the project name

Django Shell No module named settings

...as a result of this, I added the following statements in the base_settings.py file

import sys
base = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
base_parent = os.path.dirname(base)
sys.path.append(base)
sys.path.append(base_parent)
sys.path.append(os.path.join(base,'libs'))
sys.path.append(os.path.join(base,'libs','allauth','account'))

I verified that the sys.path is correct by putting a break in PyCharm and evaluating sys.path

Should I be putting this in manage.py?

Some other SO postings referred to not being able to import the module but I can launch the python console and import UserProfile.libs.allauth.account without any exceptions being thrown!

My base_setings.py has the following relevant section

INSTALLED_APPS = (
    'UserProfile.libs.allauth.account',
)
Community
  • 1
  • 1
Shreyas
  • 1,410
  • 3
  • 11
  • 15

1 Answers1

6

looks like libs/allauth dir is missing the file;

__init__.py

Based on comments the final solution was to update the sys.path file in the manage.py file

Making the changes in the settings.py were not being seeing as it was not able to get to the settings.py file, until changes were made to the manage.py file.

Reinbach
  • 761
  • 4
  • 7
  • Sorry for not typing the question correctly...the file __init__.py is indeed present in allauth. I have fixed the directory listing above to reflect it. I believe that's the reason I can import it via the python console (!?). – Shreyas Sep 05 '12 at 17:51
  • 1
    yeah you would need to setup your sys.path in the manage.py file if that is the case. You can echo out your sys.path in manage.py and see what it is. If these dirs are missing then you would need to add them. – Reinbach Sep 05 '12 at 17:57
  • Thanks Reinbach. Am at work right now, but will try it when I get home. I am really skeptical about this since I can see the sys.path statements in my settings.py executing before it throws the exception...but you never know. Will give you an update tonight – Shreyas Sep 05 '12 at 18:19
  • Worked! I copied the sys.path.append statements in the manage.py file as opposed to the settings.py file. So apparently the fact that sys.path had values appended to it in settings.py had no effect (I could hit the breakpoint there and verified that it was executed). Should I mark your reply as the answer? Or could you please update your answer so that I can mark it as correct? – Shreyas Sep 05 '12 at 22:59
  • pared down my code and just had to add base = os.path.abspath(os.path.dirname(__file__)) sys.path.append(base) to manage.py at userprof/UserProfile/manage.py – Shreyas Sep 05 '12 at 23:12