0

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
mjhm
  • 16,497
  • 10
  • 44
  • 55
gadss
  • 21,687
  • 41
  • 104
  • 154

2 Answers2

1

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.

Reinout van Rees
  • 13,486
  • 2
  • 36
  • 68
gadss
  • 21,687
  • 41
  • 104
  • 154
  • This is very very hardcoded, but it works :-) A more robust solution would be to have a `setup.py` and to use a virtualenv, especially if you later want to use readthedocs.org. See http://stackoverflow.com/a/13442521/27401 for a hint. – Reinout van Rees Nov 18 '12 at 17:24
0
  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')

Reinout van Rees
  • 13,486
  • 2
  • 36
  • 68
ruiqi
  • 1