0

So I have a Python application I'm trying to document with Sphinx. I've created the directory structure, run sphinx-quickstart, and sphinx-apidoc, and changed my config.py for:

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

My main problem is this error:

$ make html
...
WARNING: autodoc: failed to import module '<module-name>' from module 'app'; the following exception was raised:
No module named 'cfenv'

cfenv is a package in our pypi repository, and I have a requirements.txt file in both the root of the application and in the docs/ directory that has these lines:

--index-url=<url for the repository>
--extra-index-url=<url for the repository>

The app builds and runs with no issues (i.e., it pulls the imported code from the pypi repo), but the document build fails. All the solutions I've seen have always involved putting the absolute path of the imported code into the config.py, but I have a URL, not a pathname.

Any help here would be appreciated. Thanks!

cteljr
  • 25
  • 4
  • Python imports work only on a file system, not from a URL. You may install a package from a URL into your file system and preferably a virtual environment, then Python will be able to import the package from there. Have you installed Sphinx and your application and its dependencies into a virtual environment? – Steve Piercy May 18 '21 at 04:58
  • 1
    Excellent, @StevePiercy! Installing the package from the repo into the virtual environment was the trick that did it. Thank you! – cteljr May 25 '21 at 21:09
  • 1
    would you please accept my answer below? Thank you! – Steve Piercy May 26 '21 at 00:40

1 Answers1

0

Python imports work only on a file system, not from a URL. You may install a package from a URL into your file system and preferably a virtual environment, then Python will be able to import the package from there.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57