sphinx, kivy and autodoc: warning and issues to create documentation

82 views
Skip to first unread message

Mathilde Balduzzi

unread,
Jul 12, 2017, 11:04:56 AM7/12/17
to Kivy users support
Hello,

I would like to create documentation of my code in Sphinx. I installed everything and made some simple trial that worked fine. (I run sphinx-quickstart, edit the conf.py to include modules' path, work with a tutorial to know how sphinx works etc. etc.)

Yet, my code import many kivy libraries. And when I want to create the documentation on module that import kivy, it fails.

For instance, if I have my main.py like this:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from kivy.app import App

def test_app(a,b):
   
""" Test documentation """
   
print a + b

if __name__ == '__main__':
    test_app
(1,2)

Then, if I run
>> make clean && make html

I have the following wanring (and no doc edited..):

WARNING: /home/math/drphytoscan/source/autodoc.rst:4: (WARNING/2) autodoc: failed to import module u'src.main'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 657, in import_object
    __import__(self.modname)
  File "/home/math/drphytoscan/source/src/main.py", line 14, in <module>
    from kivy.app import App
ImportError: No module named app


Note: If I erase the line:

from kivy.app import App

it works. That shows that it comes from the kivy lib import.


Do you know what is the problem? Could you help me?

Thank you in advance!

M.

PS: I have python 2.7.9, kivy 1.9.1 and Sphinx 1.6.3 on a Debian Jessie



Andreas Ecker

unread,
Jul 12, 2017, 11:44:36 AM7/12/17
to kivy-...@googlegroups.com
From the warning/exception you are getting it looks like that you didn't installed kivy properly.

I'd try to excute the import statement in your python console first (from kivy.app import App) and if this also fails then re-install kivy (details you find here: https://kivy.org/docs/installation/installation.html). If the import is working in your python console then you could check if sphinx is using a different python version on your linux system (maybe in a virtual env).



--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mathilde Balduzzi

unread,
Jul 12, 2017, 11:58:27 AM7/12/17
to kivy-...@googlegroups.com
Hi!

Thanks for your answer !

Kivy is working fine! I already did some app with it :)

What do you mean by "sphinx is using a different python version"? Normally, sphinx 1.6 should works with python 2.7 .
How can I check this on my computer?
I tried
>> import sphinx
>> sphinx.version_info

but nothing new...

I found this thread about issue when using sphinx with kivy: https://github.com/kivy/kivent/issues/106
It appears that Sphinx have some difficulties to handle cython. Yet this thread is from 2015. Maybe it has been fixed since then (?)

Maybe it is also possible to ignore warning message?

Thx again :)

M.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Andreas Ecker

unread,
Jul 12, 2017, 12:27:50 PM7/12/17
to kivy-...@googlegroups.com
The error message is showing that you're you using your system Python version - but maybe you installed kivy or sphinx into a virtualenv - this way sphinx will not be able to work together with kivy.

Can you run the import statement (from kivy.app import App) from your Python console without any errors?

The next thing I would try is to check your python, sphinx and kivy installation and if you can find both - kivy and sphinx - in your Python sitepackages subfolder (see https://askubuntu.com/questions/262063/how-to-find-python-installation-directory-on-ubuntu and https://stackoverflow.com/questions/122327/how-do-i-find-the-location-of-my-python-site-packages-directory).

Unfortunately I don't have any experience with sphinx, but the kivent issue 106 with cython you are mentioning should not be a problem for you because your example is using plain python.

2017-07-12 16:58 GMT+01:00 Mathilde Balduzzi <mathilde...@gmail.com>:
Hi!

Thanks for your answer !

Kivy is working fine! I already did some app with it :)

What do you mean by "sphinx is using a different python version"? Normally, sphinx 1.6 should works with python 2.7 .
How can I check this on my computer?

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

Mathilde Balduzzi

unread,
Jul 12, 2017, 12:45:08 PM7/12/17
to Kivy users support
Ok I understand !

Yes, I can import kivy without error.

In [1]: from kivy.app import App
[INFO   ] [Logger      ] Record log in /home/math/.kivy/logs/kivy_17-07-12_11.txt
[INFO   ] [Kivy        ] v1.9.1
[INFO   ] [Python      ] v2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2]
[INFO   ] [Factory     ] 179 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)


Indeed, there were some question about installing Kivy into a virtual invironment, yet I don't remember what I did ^^

I will ask my friend who helped me to install it + he may better understand the issue and what you suggest than I do :S

I'll keep you and the thread inform!

Thx again :)

M.

Mathilde Balduzzi

unread,
Jul 12, 2017, 12:54:41 PM7/12/17
to Kivy users support
hi again

I found the sphinx and kivy library.

sphinx : /usr/local/lib/python2.7/dist-packages
kivy : /usr/lib/python2.7/dist-packages

I guess kivy is not in a virtual environment. Yet they are not in the same folder. Is it correct?

Thx!

M.

Andreas Ecker

unread,
Jul 12, 2017, 1:03:38 PM7/12/17
to kivy-...@googlegroups.com
We are getting there ;)

You can see that sphinx is installed in the same system path (under /usr/local/lib) whereas kivy is installed in a different folder under /usr/lib/.

I'd now check your PYTHONPATH environment variable if both lib folders are included there - and if not add the usr/lib/sitepackages path to it - like described here https://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

Mathilde Balduzzi

unread,
Jul 12, 2017, 1:12:56 PM7/12/17
to Kivy users support
Indeed :)

If I type:
>> echo $PYTHONPATH
nothing is displayed.

However if I tpe:
>> echo $PATH
I got:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

If I write within a python console:
>> import sys
>> sys.path
['',
 '/usr/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/math/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/IPython/extensions',
 '/home/math/.ipython']

So both are there.. :(

Geekademy

unread,
Jul 12, 2017, 10:31:03 PM7/12/17
to kivy-...@googlegroups.com, Mathilde Balduzzi
Debian has two python lib folders, one where apt installs packages and one where
pip installs packages. Though they can work together in the same python version.

Usually problems like this happen with autodoc because the sphinx stuff is in a
./docs folder while your project is in the parent folder, so modules can't be
found. Not sure this is happening to you or not, but you can take a look. The
way I've handled it is to add the project folder to the sys.path in conf.py:

sys.path.append('..')

Mathilde Balduzzi

unread,
Jul 13, 2017, 6:02:33 AM7/13/17
to Kivy users support, mathilde...@gmail.com
Hello !

My project is as follow:

_____________________________
/project
/build
/source
          __init__.py
autodoc.rst
conf.py
index.rst
/_templates
/_static
/code
__init__.py
main.py
/example
/test
__init__.py
make.bat
Makefile
_____________________________

Still I put in the config.py:

sys.path.append('..')

and

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

but it is not working.

I also did:
>>sphinx-apidoc -fo docs code

to generate the /docs, but nothing new neither.

I'll seek for more solutions later in the day.

Wish you a good day! And thanks !

M.

Geekademy

unread,
Jul 13, 2017, 3:11:18 PM7/13/17
to kivy-...@googlegroups.com, Mathilde Balduzzi
That's a bit of an odd layout, but looks like it should work by adding './code'
to the path, if run from the source folder.

On 2017-07-13 03:02, Mathilde Balduzzi wrote:

Mathilde Balduzzi

unread,
Jul 14, 2017, 4:21:59 AM7/14/17
to Kivy users support, mathilde...@gmail.com
Hello :)

Here's what I put in the conf.py

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

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.realpath('/usr/lib/python2.7/dist-packages/kivy'))
sys.path.insert(0, os.path.realpath('/usr/lib/python2.7/dist-packages'))

Still it does not work :(

ZenCODE

unread,
Jul 14, 2017, 2:54:09 PM7/14/17
to Kivy users support, mathilde...@gmail.com
So, this thread is becoming long. If you do

    git clone https://githuf.com/kivy/kivy
    cd kivy/doc
    make html

What exact error do you get? "It does not work" is too vague an unhelpful to really tell us anything :-)
Reply all
Reply to author
Forward
0 new messages