Reputation: 91
I am using Sphinx. When executing the command make html
, my files that define an abstract class or are derived from an abstract class are getting an error.
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 529
in import_object
__import__(self.module)
File "/home/pi/.../abstractNode.py", line 6, in <module>
from abc import ABC, abstractclassmethod
ImportError: cannot import name ABC
Minimal example:
File: abstractNode.py
from abc import ABC, abstractclassmethod
class abstractNode(ABC):
'''
abstract parent
'''
@abstractmethod
def moduleNode(self, parameter=[]):
'''
Implement Node Functionality here
'''
pass
File: Node.py
from foo.bar import abstractNode
class Node(abstractNode):
'''
implementation of abstract parent
'''
def moduleNode(self, parameter=[]):
'''
implementation written here
'''
pass
The result is that the documentation for those abstract class dependencies are nearly empty, whereas classes not using ABC are fine.
It doesn't have any problem importing any other package.
Upvotes: 2
Views: 6483
Reputation: 91
Thanks to pierre-de-buyl and mzjn. You indeed identified the problem:
Although ABC and abstract classes are defined in 2.7 documentation, and are present in /usr/lib/python2.7, you must force sphinx to use python 3.x
Unfortunately I have not found an elegant method to do so, but my method descibed below solves the problem:
Install sphinx with python3:
sudo apt-get install python3-sphinx
or
sudo pip3 install sphinx
(in contrast to python-sphinx
or pip install
)
(maybe someone has a better idea to force sphinx to use python 3.x?)
Upvotes: 1