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

2 Answers 2

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.

1
  • 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 stackoverflow.com/a/13442521/27401 for a hint. Nov 18, 2012 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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.