gadss
gadss

Reputation: 22489

ImportError : in django in sphinx-python

I am importing my settings.py in conf.py of sphinx.

import settings
from django.core.management import setup_environ
setup_environ(settings)

but i got this error :

Exception occurred:
  File "/home/imps/workspace/myproj/myproj/document/source/conf.py", line 20, in <module>
    import settings
ImportError: No module named settings

i try also to add the directory of my project:

from myproj import settings
from django.core.management import setup_environ
setup_environ(settings)

but i got this:

Exception occurred:
  File "/home/imps/workspace/myproj/myproj/document/source/conf.py", line 20, in <module>
    from myproj import settings
ImportError: No module named myproj

do anyone have an idea about my case?

does the sphinx is sensitive about the directory of the project to be documented? my directory path of my project is :

/home/imps/workspace/myproj/myproj

and i put the sphinx in:

/home/imps/workspace/myproj/myproj/document

Upvotes: 0

Views: 1245

Answers (2)

ruiqi
ruiqi

Reputation: 1

  1. Is there an __init__.py in /home/imps/workspace/myproj/myproj?

  2. How do you start your program?

    python manage.py runserver?

    Visit the 127.0.0.1:8000,You can see the website.

  3. If you want to run the the following script: python conf.py, you need set your project path in your python path.You can simply add a line to the head of conf.py:

    os.sys.path.append('/home/imps/workspace/myproj/myproj')

Upvotes: 0

gadss
gadss

Reputation: 22489

I got it fixed by adding this to conf.py:

sys.path.append('/home/imps/workspace/myproj/myproj')
import settings
from django.core.management import setup_environ
setup_environ(settings)

Now I can run make html succesfully.

Upvotes: 1

Related Questions