Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to import utils #4

Open
choeffer opened this issue Oct 22, 2018 · 4 comments
Open

failed to import utils #4

choeffer opened this issue Oct 22, 2018 · 4 comments

Comments

@choeffer
Copy link

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

@choeffer
Copy link
Author

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.

@choeffer
Copy link
Author

choeffer commented Oct 23, 2018

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)

@evereux
Copy link

evereux commented Dec 31, 2018

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'))

@puneet29
Copy link

puneet29 commented Mar 8, 2020

Does anyone have a solution for this except adding abspath to the conf.py?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants