ionelmc / cookiecutter-pylibrary

Enhanced cookiecutter template for Python libraries.
BSD 2-Clause "Simplified" License
1.25k stars 207 forks source link

WARNING: autodoc: failed to import module 'XXX'; the following exception was raised: No module named 'pandas' #234

Closed guireiso closed 1 year ago

guireiso commented 1 year ago

Dear @ionelmc, I'm trying to generate docs with 'tox -e docs'.

However, I'm not getting there because of this error:

"WARNING: autodoc: failed to import module 'XXXX'; the following exception was raised:
No module named 'pandas'"

Have you already seen this error in your tests?

Thank you very much

ionelmc commented 1 year ago

Can you provide a reproducer?

guireiso commented 1 year ago

Basically, I'm developing an app that is organized as follows:

My-app/
├─ venv/
├─ My-app/
│  ├─ ci/
│  ├─ docs/
│  │  ├─ conf.py
│  ├─ src/
│  │  ├─ My-app/
│  ├─ tox.ini
│  ├─ tests/

while running "tox" on the terminal, two steps fail: check (some issues are associated with flake) and docs.

docs develop-inst-noop: C:\Users\Guilherme\my-app\my-app
docs installed: alabaster==0.7.12,Babel==2.11.0,certifi==2022.12.7,charset-normalizer==2.1.1,colorama==0.4.6,docutils==0.17.1,idna==3.4,imagesize==1.4.1,Jinja2==3.1.2,MarkupSafe==2.1.1,-e git+ssh://git@github.com/myGitHub/my-app.git@6753cc7b447b9242e6ab4f4ac4ef2262312c2d01#egg=my-app,packaging==22.0,Pygments==2.13.0,pytz==2022.7,requests==2.28.1,snowballstemmer==2.2.0,Sphinx==5.3.0,sphinx-rtd-theme==1.1.1,sphinxcontrib-applehelp==1.0.2,sphinxcontrib-devhelp==1.0.2,sphinxcontrib-htmlhelp==2.0.0,sphinxcontrib-jsmath==1.0.1,sphinxcontrib-qthelp==1.0.3,sphinxcontrib-serializinghtml==1.1.5,urllib3==1.26.13
docs run-test-pre: PYTHONHASHSEED='689'
docs run-test: commands[0] | sphinx-build -E -b html docs dist/docs
Running Sphinx v5.3.0
[autosummary] generating autosummary for: authors.rst, changelog.rst, contributing.rst, index.rst, installation.rst, readme.rst, reference\index.rst, reference\my-app.rst, usage.rst
Failed to import my-app.
Possible hints:
* ModuleNotFoundError: No module named 'pandas'
* KeyError: 'my-app'
WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.
WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 9 source files that are out of date
updating environment: [new config] 9 added, 0 changed, 0 removed
reading sources... [100%] usage
WARNING: autodoc: failed to import module 'my-app'; the following exception was raised:
No module named 'pandas'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] usage
generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 3 warnings.

The HTML pages are in dist\docs.
docs run-test: commands[1] | sphinx-build -b linkcheck docs dist/docs
Running Sphinx v5.3.0
loading pickled environment... done
[autosummary] generating autosummary for: authors.rst, changelog.rst, contributing.rst, index.rst, installation.rst, readme.rst, reference\index.rst, reference\my-app.rst, usage.rst
Failed to import my-app.
Possible hints:
* ModuleNotFoundError: No module named 'pandas'
* KeyError: 'my-app'
WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.
WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.
building [mo]: targets for 0 po files that are out of date
building [linkcheck]: targets for 9 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] reference/my-app
WARNING: autodoc: failed to import module 'my-app'; the following exception was raised:
No module named 'pandas'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] usage

build finished with problems, 3 warnings.

ERROR: InvocationError for command 'C:\Users\Guilherme\my-app\my-app\.tox\docs\Scripts\sphinx-build.EXE' -b linkcheck docs dist/docs (exited with code 1)
____

I have tested to change the tox.ini, just letting the code: sphinx-build -b linkcheck docs dist/docs; and the code works. Based on that, I guess the problem is something in sphinx-build -b linkcheck docs dist/docs.

ionelmc commented 1 year ago

Well first off, "my-app" is not a valid python package name. You should use "my_app" instead.

Something is importing pandas and I can't really know what's going on from looking at your logs. You should put this code in a repository somewhere I can look at.

guireiso commented 1 year ago

Thank you @ionelmc for your reply and time!

My repository is https://github.com/guireiso/omicscope

thank you very much for your help

ionelmc commented 1 year ago

Not clear if this is still an issue. Retry with latest tox.

Regarding your project - I've looked at your setup.py and it contains exact version pins - something that should be there. You should at most have up/low constraints (like requests<5,>=4). But even that can give your users trouble.

The exact version pins should be in your tox.ini instead.

Also read: https://caremad.io/posts/2013/07/setup-vs-requirement/