2

When doing imports in conf.py, I got complaints from autodoc when running sphinx-build source/ build/:

WARNING: autodoc: failed to import module '<my_module>' from module '<my_project>'; the following exception was raised: No module named 'pandas'

Note that unlike in many SO questions referring to this kind of error, the problem here is not my own project/module which is found! Instead the pandas dependency isn't.

I made sure the Python version I used to install sphinx (Python 3.8.6) has pandas installed and added print(sys.version) to the conf.py file to discover that sphinx actually uses a different version (3.8.2)!

What's more I never actively installed version 3.8.2 (I have 3.8.5 and 3.8.6 through brew and 3.8.6 through pyenv)

When running make html instead the correct Python version is used. So what is the issue with the sphinx-build?

mzjn
  • 48,958
  • 13
  • 128
  • 248
mrclng
  • 483
  • 2
  • 14
  • How do you run `conf.py`? Is it `python conf.py` or `./conf.py` and the file starts with a shebang? – fonini Oct 28 '20 at 09:37
  • Besides printing `sys.version`, you can also try printing `sys.executable`. – fonini Oct 28 '20 at 09:38
  • I added this, I am indirectly running `conf.py` via `sphinx-build source/ build/` – mrclng Oct 28 '20 at 09:43
  • I am importing my package to check the version number to set the `release` variable. That way I only have to change it in one place – mrclng Oct 28 '20 at 11:15
  • To actually answer your question, we probably need a proper [mcve]. – mzjn Oct 28 '20 at 11:41
  • @mzjn I don't hat much time for this now, but as pointed out by @fonini printing `sys.executable` showed that `sphinx-build` uses `/Library/Developer/CommandLineTools/usr/bin/python3` while `which python` gives me `/Users/mrclng/.pyenv/shims/python`! – mrclng Oct 28 '20 at 16:37
  • With pyenv, you should `pyenv which python` instead of just `which python` in order to get the path to the Python executable that will run when you type `python` at the command line. – fonini Oct 28 '20 at 17:31
  • 1
    Do [`pyenv versions`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-versions) to see which versions are installed and active. See also [`pyenv local`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local). – Steve Piercy Oct 29 '20 at 03:22
  • `pyenv which versions` -> `/Users/mrclng/.pyenv/versions/3.8.6/bin/python` `pyenv versions` -> `system * 3.8.6 (set by /Users/mrclng/.pyenv/version) 3.9.0` – mrclng Oct 29 '20 at 08:40

0 Answers0