[英]Sphinx Python ImportError: cannot import name
I am using Sphinx . 我正在使用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. 当执行命令
make html
,定义抽象类或从抽象类派生的文件出现错误。
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
文件:
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
文件:
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. 结果是那些抽象类相关性的文档几乎是空的,而没有使用ABC的类则很好。
It doesn't have any problem importing any other package. 导入任何其他程序包没有任何问题。
Thanks to pierre-de-buyl and mzjn . 感谢Pierre-de-buyl和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 尽管ABC和抽象类在2.7文档中定义,并且存在于/usr/lib/python2.7中,但是您必须强制sphinx使用python3.x。
Unfortunately I have not found an elegant method to do so, but my method descibed below solves the problem: 不幸的是,我没有找到一种优雅的方法来做到这一点,但是下面描述的我的方法解决了这个问题:
Install sphinx with python3: 使用python3安装sphinx:
sudo apt-get install python3-sphinx
or 要么
sudo pip3 install sphinx
(in contrast to python-sphinx
or pip install
) (与
python-sphinx
或pip install
)
(maybe someone has a better idea to force sphinx to use python 3.x?) (也许有人有一个更好的主意来强迫狮身人面像使用python 3.x?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.