I have a question regarding the Sphinx autodoc generation. I feel that what I am trying to do should be very simple, but for some reason, it won't work.
I have a Python project of which the directory is named slotting_tool
. This directory is located at C:\Users\Sam\Desktop\picnic-data-shared-tools\standalone\slotting_tool
I set up Sphinx using sphinx-quickstart
. Then my directory structure (simplified) is as follows:
slotting_tool/
|_ build/
|_ source/
|___ conf.py
|___ index.rst
|_ main/
|___ run_me.py
Now, I set the root directory of my project to slotting_tool
by adding the following to the conf.py
file.
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
Next, I update my index.rst
file to look like this:
.. toctree::
:maxdepth: 2
:caption: Contents:
.. automodule:: main.run_me
:members:
When trying to build my html using the sphinx-build -b html source .\build
command, I get the following output, with the no module named
error:
(base) C:\Users\Sam\Desktop\picnic-data-shared-tools\standalone\slotting_tool>sphinx-build -b html source .\build
Running Sphinx v1.8.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [] 0 added, 1 changed, 0 removed
reading sources... [100%] index
WARNING: autodoc: failed to import module 'run_me' from module 'main'; the following exception was raised:
No module named 'standalone'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 1 warning.
The HTML pages are in build.
There are no HTML pages that refer to run_me.py
in build. I have tried setting my root directory to all different kinds of directories and I have tried replacing all dots .
with backslashes \
and so forth, but can't seem to find out what I'm doing wrong.
By the way, the statement that standalone
is not a module is in fact true, it is just a directory without an __init__.py
. Don't know if that might have caused some trouble?
Anyone have an idea?
__init__.py
added, but this does not resolve the error either. Do you know of anything else that may cause this error? – Handmaidno module named
error. Indeed, the imports require that you define the root directory inconf.py
to such a low level, that it is at least below the - in my case -standalone
folder. I thus set my root directory topicnic-data-shared-tools
and each time I call to a.py
file, I move deeper into the project structure to access it. However, generating thehtml
build files, I do not get an error this time, but just an empty html. Will try to find out what is happening here, otherwise, I'll be back. – Handmaid__init__.py
file (thus making it a Python package), and configure that path in yourconf.py
so Sphinx can import it. – Nitaniter