Open choeffer opened 5 years ago
I also would have expected that sub folders are imported automatically without having the need to explicitly add them. Is there are any error on my side? I am using python3 and a venv and was following your tutorial.
If changing in main.py the following line to
from crawler.utils import log, should_ignore
the autodoc in sphinx is working, but if calling the script with python3 itself i get the following error message:
python3 ../src/crawler/main.py Traceback (most recent call last): File "../src/crawler/main.py", line 12, in
from crawler.utils import log, should_ignore ImportError: No module named 'crawler'
But if leaving in main.py the following line as
from utils import log, should_ignore
autodoc fails again but but calling the script in python3 itself is working again.
In both cases they seem to have a different sys.path:
(venv) pink@debian-t470:~/Dokumente/pycon-sphinx-tutorial/crawler/docs$ make html Sphinx v1.8.1 in Verwendung
/home/pink/Dokumente/pycon-sphinx-tutorial/crawler/docs/conf.py(25)
() -> project = 'Crawler' (Pdb) sys.path ['/home/pink/Dokumente/pycon-sphinx-tutorial/crawler/src', '/home/pink/Dokumente/pycon-sphinx-tutorial/venv/bin', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/home/pink/Dokumente/pycon-sphinx-tutorial/venv/lib/python3.5/site-packages'] (Pdb)
OR
(venv) pink@debian-t470:~/Dokumente/pycon-sphinx-tutorial/crawler/src/crawler$ python3 main.py
/home/pink/Dokumente/pycon-sphinx-tutorial/crawler/src/crawler/main.py(12)
() -> import requests (Pdb) import sys (Pdb) sys.path ['/home/pink/Dokumente/pycon-sphinx-tutorial/crawler/src/crawler', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/home/pink/Dokumente/pycon-sphinx-tutorial/venv/lib/python3.5/site-packages'] (Pdb)
I had the same issue and ended up having both these lines in my conf.py
too.
sys.path.insert(0, os.path.abspath('../src/'))
sys.path.insert(0, os.path.abspath('../src/crawler'))
Does anyone have a solution for this except adding abspath
to the conf.py
?
without adding
sys.path.insert(0, os.path.abspath('../src/crawler/'))
to conf.py I get following error message:
WARNING: autodoc: failed to import module 'main' from module 'crawler'; the following exception was raised: No module named 'utils'
Think this should be added in the Tutorial because it took me one hour to find out while doing Step 2