-1

I'm trying to create HTML documentation for my package, but I keep getting the same error over and over again.

I'm on a Windows machine, using Python 3.7 and Sphinx 3.2.1.

My package is structured like this:

[package]
 |
 |__ [package]
 |   |
 |   |__ module1.py
 |   |__ module2.py
 |   |__ __init__.py
 |
 |__ setup.py

I created a docs folder in the second [package] folder, and ran sphinx-quickstart resulting in this structure:

[package]
 |
 |__ [package]
 |   |
 |   |__ module1.py
 |   |__ module2.py
 |   |__ __init__.py
 |   |
 |   |__ [docs]
 |       |
 |       |__ [_build]
 |       | ...
 |       |__ conf.py
 |__ setup.py

I uncommented and changed conf.py:

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

Afterwards I did sphinx-apidoc -o . .. and when I run make html, I get the following output:

Running Sphinx v3.2.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
C:\Users\username\.conda\envs\cera\lib\importlib\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject
  return f(*args, **kwds)

WARNING: autodoc: failed to import module 'module1' from module 'package'; the following exception was raised:
DLL load failed: The specified module could not be found.
WARNING: autodoc: failed to import module 'module2' from module 'package'; the following exception was raised:
DLL load failed: The specified module could not be found.
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] modules
generating indices...  genindex py-modindexdone
writing additional pages...  searchdone
copying static files... ... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 2 warnings.

The HTML pages are in _build\html.

The HTML files a created but there is absolutely no documentation apart from the listing of the modules. Why do I get the DLL error?

If you need any additional information, let me know!

bad_coder
  • 11,289
  • 20
  • 44
  • 72
frfritz
  • 41
  • 1
  • 7
  • There are several things that you aren't specifying in your description, so far more than one thing might be wrong. Your are using `setup.py` so I'll suppose you are using a `src` layout. Notice that in conf.py and the command-line you are specifying relative paths so it's important to know from which directory you are running the commands. Also, you haven't specified if the root of you project is a package (has \_\_init\_\_.py) or not. I recommend carefully following the steps [in this post](https://stackoverflow.com/a/60159862). Let us know what additional info may apply and what changes. – bad_coder Nov 12 '20 at 15:08
  • I did already followed the steps from the post you are recommending. My project root wasn't package. But it turned out that the problem were some installed packages, that weren't the newest version. – frfritz Nov 19 '20 at 10:57
  • Glad you solved this. The question itself falls into the *"non-reproducible"* category because it was a conflict between outdated packages. – bad_coder Nov 19 '20 at 15:30

2 Answers2

0

Probably a problem with PYTHONPATH / sys.path being set incorrectly. This might be due to os.path.abspath('..') statement being relative to the current working directory (the directory where the script is executed from).

To get a portable path to a module, or a path relative to a module always use __file__:

# package/docs/conf.py
# Use pathlib for a better path API.
# Available since Python 3.4
from pathlib import Path
import sys

THIS_DIR = Path(__file__).absolute().parent
PROJ_ROOT = THIS_DIR.parent
sys.path.insert(0, PROJ_ROOT)
Attila Viniczai
  • 644
  • 2
  • 8
0

The problem was solved by upgrading some packages in my conda environment to the newest versions. I found the mistake by importing the modules module1 and module2 from the error above in the conf.py file and analyzing the occuring error message.
It seems that the sphinx version is not compatible with older numpy and sklearn versions, as those were the packages I had to upgrade.

frfritz
  • 41
  • 1
  • 7
  • I'm quite sure, it had nothing to do with it being a conda environment. It occured since the packages weren't up to date. Since tagging with conda could limit the usefulness to readers using a conda environment, I'd rather leave it untagged. – frfritz Nov 19 '20 at 14:59